[antlr-interest] Deciphering the TreeWalker error message ...

Kevin J. Cummings cummings at kjchome.homeip.net
Thu Jul 21 09:36:50 PDT 2011


On 07/21/2011 02:48 AM, Gary Miller wrote:
> 3.
> rule :
>   ^(subrule otherrule)
> ;
> Just looks wrong.

I am under the impression that a treewalker rule should be rooted in a 
TOKEN, not a subtree.  The few treewalker grammars I have written always 
have rules that look like ^(TOKEN some other rules or TOKENS)
If a subrule reference is not allowed to be the root of the tree being 
parsed, I would have thought that ANTLR would have issued an error when 
the tree grammar was run through ANTLR....

I could be wrong with my assumption here, but I have never gotten into 
trouble by assuming it (so far).

Often this involves me collapsing my treewalker rules together.  For 
example, if I have 12 parse rules to accurately describe precidence in 
an expression, my treegrammar might have 12 alternations, one for each 
possibly different rooted TOKEN when walking them.  This makes my 
treegrammars (much) smaller than my parser grammars.

> If you inline (expand) out what you have written you would get
> compoundExpression
> : ^((SUB_EXPR ^(PAREN_SCLAR_EXPRESSION sclarExpression+) conversion_clause )
> ;
> The ^(( is impossible
> Make all you start tree look like ^(TOKEN ...)
> ^(sign sse=sclarSubExpression) therefore also look wrong.

Yes, treegrammar rules can refer to other rules, but the rooted 
expressions: ^() should be rooted with TOKENs.

-- 
Kevin J. Cummings
kjchome at verizon.net
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)


More information about the antlr-interest mailing list