[antlr-interest] 2 C-target questions

Corno Schraverus antlr-interest at schraverus.com
Wed Oct 3 02:22:29 PDT 2007


Hi all,

 

I have 2 C-target questions, could anybody help me with that.

 

1)

If I have labeled a token (like this: myToken=IDENT ), how can I then get
the text of that token? (similar like myToken->getText() for C++ in ANTLR2).

I did find something about the GETTEXT macro while googling but I couldn't
get it to work.

 

2)

The following construct used to work in antlr2, in antlr3 it doesn't. The
variable x is placed in a nested block in the generated code and is
therefore not accessible outside that block.

Is this an error on my side, a bug in antlr or a bug in the
c-stringtemplate?

 

----

grammar test;

 

options

{

      language=C;

}

 

test

:

      {

            char x;

      }

      (

            'a' { x = 'a'; }

      |

            'b' { x = 'b'; }

      )

;

---

 

This becomes:

 

----

{

    {

      char x;   <----- declaration

    }

    {

      ------snip------

      switch (alt1) 

      {

      case 1:

          {

            MATCHT(4, &FOLLOW_4_in_test35); 

 

            {

                 x = 'a'; <------ failing assignment

            }

 

          }

          break;

      ------snip-------

      }

    }

 

}

 

 

Greetings,

 

Corno

 

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071003/e4544690/attachment.html 


More information about the antlr-interest mailing list