[antlr-interest] Possible bug with backtrack-generated predicate methods

Bart Kiers bkiers at gmail.com
Sat Nov 26 01:29:16 PST 2011


On Sat, Nov 26, 2011 at 9:58 AM, franck102 <franck102 at yahoo.com> wrote:

> In fact the tree has been constructed by the leading (ID->ID),


That tree only exists inside your parenthesis, AFAIK. You can't reference
it outside it (well, you can, but it will be `null`).


So here is exactly what I am trying to do, there is probably a better way
> than what I have (untested pseudo-grammer, but you should get the idea):
>
> expr
>    :    ( prefix -> prefix ) ( suffix -> /* *insert prefix as first child
> of suffix and return suffix * */ ) *
>
> prefix : ID;
>
> suffix
>    :    DOT ID     -> ^( DOT ID )
>    |    '[' expr ']'  -> ^( INDEX expr )
>
> I guess I could use a scope to pass down the prefix; or have suffix return
> both the root type and a flat list and build the tree in expr; but both
> seem
> painful to get right typing wise...
>
>
Yes, it's a pain compared to simple passing the tree as a parameter, but
that's the "penalty" for turning on global backtracking [1].

Bart.


[1]
http://www.antlr.org/wiki/display/ANTLR3/How+to+remove+global+backtracking+from+your+grammar


More information about the antlr-interest mailing list