[antlr-interest] Something like EOF token for tree parsers?

Bryan Ewbank ewbank at gmail.com
Fri Jun 9 18:03:50 PDT 2006


There's not a feature; I rolled my own by creating an "endKids" rule
that looks something like this; calling it "andNothingElse" is good
too:

   endKids [ AST parent ]
   :
         (   badkid:
                  {
                       // throw an exeception -- too many children for
/parent/ node.
                  }
         )?
   ;

This may force you to add a few "greedy=true" options, but I've found
the benefit outweighs the cost.

Note that you could create a separate audit pass that verifies tree
shape, to be used only in debug mode, rather than making your true
tree passes more complex.


On 6/9/06, Jörg Rathlev <joerg at jrsoftware.de> wrote:
> In normal parsers, I can use the special "EOF" token to make sure I have
> reached the end of the file and I am not ignoring any invalid input at
> the end of the file. Does a similar feature exist for subtrees in tree
> parsers?


More information about the antlr-interest mailing list