tree - ANTLR syntax error unexpected token: + -


hi have small problem in antlr tree grammar. using antlrworks 1.4. in parser grammar have rule this:

declaration :       'variable' identifier ( ',' identifier)* ':' type ';' ->    ^('variable' identifier type)+ 

so wanted 1 tree per each identifier.

and in tree grammar left rewrite rules:

declaration :     ^('variable' identifier type)+ 

but when check grammar got syntax error unexpected token +. , + sign @ end of declaration rule in tree grammar. doing wrong?

parser grammar works fine , builds ast tree expected. generated lexer , parser c# , test input.

when parsing source:

variable a, b, c : int; 

you're trying construct ast looks like:

variable variable variable     /        |        \            b         c   /          |          \ int         int         int 

but since 'variable' , type same token, see no need create duplicate nodes. why not do:

declaration   :  'variable' identifier ( ',' identifier)* ':' type ';'       -> ^('variable' type identifier+)   ; 

which create ast like:

 variable   / | | \ int b  c 

?


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -