[antlr-interest] Conversion V2 to V3
David Wigg
wiggjd at bcs.org.uk
Thu Mar 20 04:41:23 PDT 2008
In "Migrating from Antlr 2 to Antlr 3" it says under "Changing the type of
tokens in the lexer" that we need to change,
{$setType(TOKEN);} to {$type = TOKEN;}
In V2 I was able to set a token name using e.g. "{_ttype =
HEXADECIMALINT;}"
but when I replace this with {$type = HEXADECIMALINT;) it doesn't work and I
get warning (105)
"No lexer rule corresponding to token: HEXADECIMALINT".
Relevant code shown below,
Please could someone let me know where I am going wrong or point out where I
can find the answer.
I searched (literally) the antlr site but couldn't find anything else.
tokens
{
OPERATOR = 'operator';
OCTALINT;
DECIMALINT;
HEXADECIMALINT;
FLOATONE;
FLOATTWO;
}
literal
: OCTALINT
| DECIMALINT
| HEXADECIMALINT
| CharLiteral
| WCharLiteral
| (StringLiteral|WStringLiteral)+
| FLOATONE
| FLOATTWO
| 'true'
| 'false'
;
Number
:
( (Digit)+ ('.' | 'e' | 'E') )=>
(Digit)+
( '.' (Digit)* (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01
| Exponent {_ttype = FLOATTWO;} //Zuo 3/12/01
) //{_ttype = DoubleDoubleConst;}
(FloatSuffix //{_ttype = FloatDoubleConst;}
|LongSuffix //{_ttype = LongDoubleConst;}
)?
|
('...')=> '...' {_ttype = ELLIPSIS;}
|
'.' {_ttype = DOT;}
( (Digit)+ (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01
//{_ttype = DoubleDoubleConst;}
(FloatSuffix //{_ttype = FloatDoubleConst;}
|LongSuffix //{_ttype = LongDoubleConst;}
)?
)?
|
'0' ('0'..'7')* //{_ttype = IntOctalConst;}
(LongSuffix //{_ttype = LongOctalConst;}
|UnsignedSuffix //{_ttype = UnsignedOctalConst;}
)* {_ttype = OCTALINT;}
|
'1'..'9' (Digit)* //{_ttype = IntIntConst;}
(LongSuffix //{_ttype = LongIntConst;}
|UnsignedSuffix //{_ttype = UnsignedIntConst;}
)* {_ttype = DECIMALINT;}
|
'0' ('x' | 'X') (HexadecimalDigit)+ //('a'..'f' | 'A'..'F' | Digit)+
//{_ttype = IntHexConst;}
(LongSuffix //{_ttype = LongHexConst;}
|UnsignedSuffix //{_ttype = UnsignedHexConst;}
// )* {_ttype = HEXADECIMALINT;} JDW_080320
)* {$type = HEXADECIMALINT;}
;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080320/756bf7ad/attachment.html
More information about the antlr-interest
mailing list