• Russ Cox's avatar
    [dev.cc] cmd/yacc: introduce yyParser to expose parser state · c7fa3c62
    Russ Cox authored
    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/4850Reviewed-by: 's avatarRob Pike <r@golang.org>
    c7fa3c62
Name
Last commit
Last update
..
archive Loading commit data...
bufio Loading commit data...
builtin Loading commit data...
bytes Loading commit data...
cmd Loading commit data...
compress Loading commit data...
container Loading commit data...
crypto Loading commit data...
database/sql Loading commit data...
debug Loading commit data...
encoding Loading commit data...
errors Loading commit data...
expvar Loading commit data...
flag Loading commit data...
fmt Loading commit data...
go Loading commit data...
hash Loading commit data...
html Loading commit data...
image Loading commit data...
index/suffixarray Loading commit data...
internal/syscall Loading commit data...
io Loading commit data...
lib9 Loading commit data...
libbio Loading commit data...
liblink Loading commit data...
log Loading commit data...
math Loading commit data...
mime Loading commit data...
net Loading commit data...
os Loading commit data...
path Loading commit data...
reflect Loading commit data...
regexp Loading commit data...
runtime Loading commit data...
sort Loading commit data...
strconv Loading commit data...
strings Loading commit data...
sync Loading commit data...
syscall Loading commit data...
testing Loading commit data...
text Loading commit data...
time Loading commit data...
unicode Loading commit data...
unsafe Loading commit data...
Make.dist Loading commit data...
all.bash Loading commit data...
all.bat Loading commit data...
all.rc Loading commit data...
androidtest.bash Loading commit data...
clean.bash Loading commit data...
clean.bat Loading commit data...
clean.rc Loading commit data...
make.bash Loading commit data...
make.bat Loading commit data...
make.rc Loading commit data...
nacltest.bash Loading commit data...
race.bash Loading commit data...
race.bat Loading commit data...
run.bash Loading commit data...
run.bat Loading commit data...
run.rc Loading commit data...