[antlr-interest] Lexical token with fix length

Stefan Wohlgemuth stefan.wohlgemuth at aloba.ch
Fri Jun 29 05:49:33 PDT 2007


Hi
I'm trying to define a grammar which has tokens with a fix length. What
is the best way to do this?

I've tried it with this:

test  :     N1 N2;

N1  :  NDigits[1] ;

N2  :  NDigits[2] ;

fragment
NDigits[int n]
   :
   {$n==1}?=> Digit
   |
   {$n==2}?=> Digit Digit
   ;

Digit :    '0'..'9';


But I get a compile error in the public void mTokens() method of my
Lexer class because the variable n is not known there.

Thanks

Stefan



-- 
aloba ag
Lyssachstrasse 15
CH-3400 Burgdorf

phone  +41 34 424 17 70
fax    +41 34 424 17 74
mobile +41 78 601 41 14


More information about the antlr-interest mailing list