[prev in list] [next in list] [prev in thread] [next in thread] 

List:       antlr-interest
Subject:    [antlr-interest] C++ beginner questions
From:       ncuomo () gmail ! com (Nicola Cuomo)
Date:       2005-09-30 10:45:13
Message-ID: 1971701424.20050930193827 () gmail ! com
[Download RAW message or body]

Hi,  i'm  also  using  C++  with  antrl  and some examples can surelly
clarify it's use

Friday, September 30, 2005, 6:08:19 PM, Peggy Fieland wrote:
> C++ Lexer its $getText. For example:

> IDENT: (ID_START_LETTER) (ID_LETTER)*
> {
>  std::string s = $getText;
>        $setText( LowerCase(s) ); }
> resolving ambiguities:  syntactic or semantic
> predicates

It's possible to do that also in the parser??

---
spec
        : zum (zum)* { std::cout << $getText << std::endl; }
        ;

zum
        : UNDERLINE CONST_IDENT 
        ;
---

Compiling this give me the error

underline.g: In member function `void TestParser::spec()':
underline.g:20: error: `text' undeclared (first use this function)
underline.g:20: error: (Each undeclared identifier is reported only once for
   each function it appears in.)
underline.g:20: error: `_begin' undeclared (first use this function)

As  far  as  construction own type during parsing i'm getting on using
returns/passing role parameter something like that:

variableListInit returns [list<VariableInit> rinitVariable]
{ 
        VariableInit tvariableInit;
        VariableInit tvariableInits;
}
  : tvariableInit=variableInit { rinitVariable.push_back( tvariableInit ); }
        (COMMA tvariableInits=variableInit { rinitVariable.push_back( tvariableInits ); } )*
  ;

variableInit returns [VariableInit rvariableInit]
{
        string texpression1;
        string texpression2;
        
}
        : texpression1=expression EQUAL texpression2=expression
        { rvariableInit.name = texpression1;  rvariableInit.value = texpression2;} 
        ;

and it seem to work.
-- 
 Nicola                            mailto:ncuomo@gmail.com

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic