[antlr-interest] Error nodes created upon syntax error
Terence Parr
parrt at antlr.org
Sun Dec 2 11:24:55 PST 2007
hi,
Currently syntax errors cause invalid trees and possibly even runtime
exceptions when building ASTs. What we really need I believe is to
have rules that encounter syntax errors return an ERROR node of some
sort that records where the error occurred and, with luck, the tokens
consumed during recovery. I started an improvement request:
http://www.antlr.org:8888/browse/ANTLR-193
The basic idea is that ERROR nodes get used in place of ASTs that
would normally be produced by rule indications. For example, the
following rule would return a valid AST except for the subtrees
associated with rule refs in encountering syntax errors:
forDecl : 'for' '(' decl ';' expr ';' expr ')' stat -> ... ;
If there is an error inside decl, the tree would return
^('for' ERROR subtree-expr subtree-expr)
This effectively means that I must turn off the single token
insertion and deletion that occurs automatically within a single
rule. If a syntax error occurs, the immediately surrounding rule
must terminate in return an error node.
Does this make sense? I would like to stick this into 3.1 release.
Ter
More information about the antlr-interest
mailing list