[antlr-interest] Grammar puzzle....

Randall R Schulz rschulz at sonic.net
Thu Jul 12 07:32:06 PDT 2007


On Thursday 12 July 2007 06:59, Lloyd Dupont wrote:
> I made some progress on this problem:
> apparently in this rule:
> ========
> identifier: ( xaml=ID COLON )? id0=ID
>   ( DOT id+=ID )*
>   -> ^( ID[$id0] ^( XAMLNS[$xaml] ) ^( ID[$id0] $id0 /*$id+*/ )  )
>  ;
> ========
> the fact that "(xaml=ID COLON)?" is optional (?) but that I used it
> all the time in the tree generation *might be* the cause of the
> trouble.
>
> I guess I could *solve* the problem with
>   -> ^( ID[$id0] ^( XAMLNS[$xaml] )?  ^( ID[$id0] $id0 /*$id+*/ )  )
> instead of
>   -> ^( ID[$id0] ^( XAMLNS[$xaml] ) ^( ID[$id0] $id0 /*$id+*/ )  )
>
> but that's no good, for my generated tree to be easy to use I always
> want the 2nd member to be the XAMLNS node, even though mpty. How
> could I rewrite my rule so that the tree always contains such a node,
> wether or not it has been found?

I'd probably write the production with alternatives, allowing you to 
rewrite it independently in the case where ID COLON is present and the 
case where it is absent. If you want the resulting AST fragment to have 
the same shape, put a dummy value in for the ID or whatever it gets 
from the XAMLNS array.

Are you working on Extensible Application Markup Language?


Randall Schulz


More information about the antlr-interest mailing list