[antlr-interest] How to split int a, b:
Arto Viitanen
arto.viitanen at pp4.inet.fi
Mon Oct 1 06:42:53 PDT 2007
On antlr-interest-request at antlr.org "Christian Andersson"
<dt05ca4 at student.lth.se> wrote:
> I have this type declaration below:
>
> int a,b;
>
>
> My simple grammar looks like the following:
>
> vardecl
> :type declarator_list ';' ->^(DECL type declarator_list)
> ;
>
> declarator_list
> : ID (',' ID)* ->^(ID)+
> ;
>
> My problem is that I want to split up int a,b; into two
> separate declarations in my AST without moving the declarator_list rule
> up to the vardecl rule.
>
On a grammar for my language I have:
varDeclaration
:
'var' ID ( ',' ID )* ISTYPE typeDenoter
( PREDEF expression -> ^(DECL 'var' ID typeDenoter expression)+
| -> ^(DECL 'var' ID typeDenoter)+
)
;
I use -> for ISTYPE and | for PREDEF, so I can use
var a, b -> integer | 3 ;
and
var a, b -> integer ;
So, move the declarator_list up to the vardecl rule and the + after the
tree.
--
Arto Viitanen
More information about the antlr-interest
mailing list