[antlr-interest] End of child list in tree parser

Bryan Ewbank ewbank at gmail.com
Mon Jan 30 05:25:55 PST 2006


There's nothing directly in antlr; I've found it useful to create a
standard "nothingElse" production that reports an error if it matches
anything.  It keeps me honest in my tree parsing without being too
intrusive:

nothingElse [ ... ] // pass parent to this production, for error messages
:
   (
      err:. // any node matched is a problem...
      {
         // blammo - encountered node #err as illegal extra child of parent
      }
   )?
;

Now, use this wherever you need it.

formalParameter = #(op:FORMAL_PARAMETER IDENT IDENT nothingElse[op] ) ;

I use it in my audit tree walks, not in the main tree transformation
passes, simply to keep things separate and too allow easy removal of
the tree audits for production use.

On 1/26/06, David Ray <ray at soartech.com> wrote:
> In an ANTLR tree parser, is there any special token I can match against
> for "end of child list", kind of like EOF in a non-tree parser?  I'm
> writing a validator for the structure of my AST and I'd like to make
> sure there aren't any trailing nodes.


More information about the antlr-interest mailing list