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

Jörg Rathlev joerg at jrsoftware.de
Fri Jun 9 14:15:39 PDT 2006


Hi,

in a tree parser, can I somehow make sure I have matched all children of
a tree?

I have just run into a bug in the java15.tree.g, in rule methodHead it
uses the following code for parsing parameter declarations:
#( PARAMETERS (parameterDef)* )
But it should be:
#( PARAMETERS (parameterDef)* (variableLengthParameterDef)? )

This bug is easily fixed, but it is not easily found because ANTLR won't
complain when the parameters subtree has an additional child at its end
that is not matched by "parameterDef". Instead, variable length
parameters are silently ignored.

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?


Thanks
Joerg


More information about the antlr-interest mailing list