[antlr-interest] executing actions while recovering from syntax
errors
Terence Parr
parrt at cs.usfca.edu
Fri Apr 8 17:46:24 PDT 2005
Hi,
Following Josef Grosch's nice error recovery work in CoCo, ANTLR v3
goes into an "error recovery mode" upon syntax error. It invokes
reportError() and then recover() (with an exact FOLLOW set). After
recovery, it attempts to continue parsing. Until a token is
successfully matched, however, ANTLR is still in "recovery mode"
meaning that no more messages will be spit out.
So, should I be executing actions during recovery mode? Seems to me
that until the next we match a token properly, actions may not be
executing in the environment they expect. For example,
decl : type ID '=' expr {action2} ';' ;
....
expr : ... {action1} ... ;
If an error occurs in expr, action1 may not be executed. After
recovery (consuming tokens to resync), expr returns to the invoker:
decl. At this point, action2 may fail (with an exception or just
produce bad results) because action1 didn't execute. ANTLR is back out
of recovery mode when it sees the ';' probably. At that point, it may
be ok to execute actions.
'course once a syntax error occurs, one could argue no action is "safe".
Anyway, putting a guard around every action looks gross and takes
time/space (oh, and I guess is no guarantee it's safe):
if ( !recoveryMode ) { action }
Anybody wanna comment? For now, the actions are unguarded.
Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
More information about the antlr-interest
mailing list