[antlr-interest] Function Call,
Bryan Ewbank
ewbank at gmail.com
Wed Jun 29 03:45:28 PDT 2005
I find it's a great help to use the tracing utility in ANTLR, because
it shows a list of the productions matched, rather than letting my
eyes go where I "know" it will go. Sometimes the two are very
different.
There's two problems; the first is that the alternative for
METHOD_CALL explicitly matches ELIST:
// problem in original tree grammar - doesn't dive into ELIST tree
#( METHOD_CALL ELIST )
It should instead use a subrule; perhaps it should be:
// tree grammar to drill into the subtree rooted at ELIST
#( METHOD_CALL expression )
The second problem is that the tree grammar for ELIST doesn't match
the parser output. The parser produces this tree for a function call:
#( METHOD_CALL #(ELIST e1 e2 e3) )
// the name of the function is the text of the METHOD_CALL node
However, the tree walker (and your example) don't match this because
they place an ID node below the ELIST:
// problem in original tree grammar
#(ELIST ID expression)
To match the input grammar, this should instead read:
// tree production to match that produced by the parser
#(ELIST ( expression )* )
You can also collapse these into one production in the tree grammar, thus:
// may as well write it this way; first two levels are known...
#( METHOD_CALL #( ELIST ( expression )* ) )
Hope this helps,
- Bryan Ewbank
More information about the antlr-interest
mailing list