[antlr-interest] Re: Backtrack option breaks AST rewrite

Thomas Brandon tbrandonau at gmail.com
Sat Jul 22 23:37:45 PDT 2006


After a little debugging the issue seems to be with the
prefixWithSynPred helper in ANTLRParser.  This gets called for stuff
in rewrite blocks and the generated syntactic predicates cause the
codegen error. The relevant call hierarchies are:
rewrite_element
  ebnfSuffix
    prefixWithSynPred
for rewrite trees and:
rewrite_ebnf
  setToBlockWithSet
    prefixWithSynPred
for non-tree rewrites.
Removing the call to prefixWithSynPred from these rules when in
rewrite blocks seems to fix the error.

Tom.

On 7/22/06, Thomas Brandon <tbrandonau at gmail.com> wrote:
> In Antlr 3.0b3 setting the backtrack option seems to break parsing of
> tree rewrites using closures. This grammar:
> grammar CParser;
> options {
>     backtrack=true;
>     output=AST;
> }
> tokens { TU; }
> translation_unit
>         : external_declaration+
>           -> ^( TU external_declaration+ /*Err here*/)
>         ;
> external_declaration
>         : 'a'
>         ;
>
> gives errors:
> 0:0: syntax error: codegen: <AST>:0:0: unexpected AST node: synpred3
> 13:13: expecting EOB, found 'external_declaration'
> (13,13 is at the end of the tree rewrite block, as indeicated)
> Removing the backtrack option fixes it, as does removing the closure
> on the rewrite rule (i.e. "-> ^( TU external_declaration)").
>
> Thanks,
> Tom.
>


More information about the antlr-interest mailing list