Plan 9 from Bell Labs’s /usr/web/sources/contrib/apm/yacc-go/readme

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


yacc: fixes and support for the Go grammar

This description is an elaboration of the
one in my mail sent to 9fans¹.  There were
two small bugs in the patch that I posted.
I sent these changes to the NIX development
mailing list for review² and in December
they were committed to the NIX codebase.

I've tested this change on all the .y files
in /sys/src/cmd and it appears to work fine.

1. The %error-verbose directive implemented
   by GNU Bison is ignored.

2. A description of the final grammar is
   printed before the state descriptions in
   y.output.  This is needed to produce the
   fancy error messages that Russ added to
   the Go compiler.

3. The 'x' format for character literals is
   now used instead of prefixing with a space.
   This was the easiest way to appease the Go
   code in src/cmd/gc/lex.c:/yytfix.  I also
   think it makes error messages look nicer.

4. The YYEMPTY define is now used to clear the
   lookahead token (instead of an explicit -1).
   Bison uses -2 for this purpose and the Go
   compiler depends on this value to determine
   the correct line number for parse errors.

5. yychar and yystate are now globals so they
   can be inspected by external code.  This is
   the second part of the change to support
   Go's fancy error messages.

6. C++ style comments are handled in actions.

7. YYERROR is now also defined in /sys/lib/yaccpar.

Also, it's important that the yacc binaries
are updated before trying to build the whole
tree since the parser files now expect the
YYEMPTY definition in y.tab.c.


Notes:
1. http://9fans.net/archive/2011/11/81
2. http://codereview.appspot.com/5415048
3. http://code.google.com/p/nix-os/source/detail?r=3dd2bfb35f81

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.