ANTLR not accepting tokens in tree parser...
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Charles_Ellis
Posted On:   Monday, February 14, 2005 12:43 PM

I'm sure there's a very simple explanation of why it doesn't work... The explanation of how I should go about fixing it, however, is probably more complicated. The offending code is: scale returns [int s] //146 { s=1; } //147 : #(T_FT) { s=12; } //148 | #(T_SC) { s=1000; } //149 | #(T_DG) { s=100; } //150 ; //151 ANTLR Parser Generator Version 2.7.5 (20050128) 1989-2005 jGuru.com routes.g:148:19: rule classDef trapped: routes.g:148:19: unexpected token: T_FT error: aborting grammar 'RouteTreeWalker' due to errors Exiting due to errors.    More>>

I'm sure there's a very simple explanation of why it doesn't work... The explanation of how I should go about fixing it, however, is probably more complicated.





The offending code is:



			
scale returns [int s] //146
{ s=1; } //147
: #(T_FT) { s=12; } //148
| #(T_SC) { s=1000; } //149
| #(T_DG) { s=100; } //150
; //151


ANTLR Parser Generator Version 2.7.5 (20050128) 1989-2005 jGuru.com

routes.g:148:19: rule classDef trapped:

routes.g:148:19: unexpected token: T_FT

error: aborting grammar 'RouteTreeWalker' due to errors

Exiting due to errors.



T_FT, etc. are defined as literal tokens in the token parser.





As for what I'm trying to do...

I have in my AST several places where there would be a token matching an integer, with a child node that is one of the T_* tokens. Depending on what the token is, I want to multiply the integer token by a scale:



			
rescale
{ int r; int a; }
:#(d:DIST a=scale){r=Integer.parseInt(d.getText()); r*=a; d=Integer.ToString(r);}
:#(h:TIME a=scale){r=Integer.parseInt(t.getText()); r*=a; t=Integer.ToString(r);}
:#(h:HEAD a=scale){r=Integer.parseInt(h.getText()); r*=a; h=Integer.ToString(r);}
;


As you can probably see, I'm still new, and a bit confused, about the best way to work with an AST...



The full grammar is here: http://eugeneciurana.com/pastebin/pastebin.php?show=5280    <<Less
About | Sitemap | Contact