c7fa3c625e
Historically, yacc has supported various kinds of inspections and manipulations of the parser state, exposed as global variables. The Go implementation of yacc puts that state (properly) in local stack variables, so it can only be exposed explicitly. There is now an explicit parser type, yyParser, returned by a constructor, yyNewParser. type yyParser interface { Parse(yyLexer) int Lookahead() int } Parse runs a parse. A call to the top-level func Parse is equivalent to calling yyNewParser().Parse, but constructing the parser explicitly makes it possible to access additional parser methods, such as Lookahead. Lookahead can be called during grammar actions to read (but not consume) the value of the current lookahead token, as returned by yylex.Lex. If there is no current lookahead token, Lookahead returns -1. Invoking Lookahead corresponds to reading the global variable yychar in a traditional Unix yacc grammar. To support Lookahead, the internal parsing code now separates the return value from Lex (yychar) from the reencoding used by the parsing tables (yytoken). This has the effect that grammars that read yychar directly in the action (possible since the actions are in the same function that declares yychar) now correctly see values from the Lex return value space, not the internal reencoding space. This can fix bugs in ported grammars not even using SetParse and Lookahead. (The reencoding was added on Plan 9 for large character sets. No Plan 9 programs using yacc looked at yychar.) Other methods may be added to yyParser later as needed. Obvious candidates include equivalents for the traditional yyclearin and yyerrok macros. Change-Id: Iaf7649efcf97e09f44d1f5bc74bb563a11f225de Reviewed-on: https://go-review.googlesource.com/4850 Reviewed-by: Rob Pike <r@golang.org> |
||
---|---|---|
api | ||
doc | ||
include | ||
lib/time | ||
misc | ||
src | ||
test | ||
.gitattributes | ||
.gitignore | ||
AUTHORS | ||
CONTRIBUTING.md | ||
CONTRIBUTORS | ||
favicon.ico | ||
LICENSE | ||
PATENTS | ||
README.md | ||
robots.txt |
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
For documentation about how to install and use Go, visit https://golang.org/ or load doc/install-source.html in your web browser.
Our canonical Git repository is located at https://go.googlesource.com/go. (There is a mirror of the repository at https://github.com/golang/go.)
Please report issues here: https://golang.org/issue/new
Go is the work of hundreds of contributors. We appreciate your help!
To contribute, please read the contribution guidelines: https://golang.org/doc/contribute.html
Please note that we do not use pull requests.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
--
Binary Distribution Notes
If you have just untarred a binary Go distribution, you need to set the environment variable $GOROOT to the full path of the go directory (the one containing this file). You can omit the variable if you unpack it into /usr/local/go, or if you rebuild from sources by running all.bash (see doc/install-source.html). You should also add the Go binary directory $GOROOT/bin to your shell's path.
For example, if you extracted the tar file into $HOME/go, you might put the following in your .profile:
export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin
See https://golang.org/doc/install or doc/install.html for more details.