[antlr-interest] RES: Tree rewrite rule problem

Nilo Roberto C Paim nilopaim at gmail.com
Tue Sep 25 14:06:32 PDT 2012


Hi, Juanca.

 

Mysterious ways indeed... you are right!

 

Replacing $i1 by ID made the trick. And breaking some rules in sub-rules, the tree generated becomes what I initially expected.

 

Thanks a lot for your assistance!

 

Best regards,

Nilo

 

De: juancarlo.anez at gmail.com [mailto:juancarlo.anez at gmail.com] Em nome de Juancarlo Añez
Enviada em: terça-feira, 25 de setembro de 2012 11:37
Para: Nilo Roberto C Paim
Cc: antlr ANTLR
Assunto: Re: [antlr-interest] Tree rewrite rule problem

 

NIlo,

 

For me, tree rewriting works in mysterious ways...

 

Replace the $i1 by ID and everything should be fine.

 

At other times when you need help with disambiguation, create "dummy" rules that you can reference from within other rules:

 

expre: .... ;

 

expre1: expre;

 

-- Juanca 

On Mon, Sep 24, 2012 at 10:18 PM, Nilo Roberto C Paim <nilopaim at gmail.com> wrote:

Hi, all.



I have the following rule on my grammar:



expr

  :

  i1=ID

  (

    compOp boolOp

      ->

        ^(BOOLEXPR $i1 compOp boolOp)

    | (NOT)? NUMERIC

      ->

        ^(BOOLEXPR $i1 NOT? NUMERIC)

    |

      ->

        ^(BOOLEXPR $i1)

  )

  ;



Problem: the parsing  is done correctly, but the resulting tree contains
only the imaginary node BOOLEXPR, with no children. If I put a
System.out.println as action for the alternatives, It shows me correctly,
but anyway, the tree is corrupt.



Any hints?



TIA.



Nilo - Brazil


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address





 

-- 
Juancarlo Añez



More information about the antlr-interest mailing list