[antlr-interest] Lexer syntactic predicates
chintan rao
chintanraoh at gmail.com
Mon Jun 18 18:53:10 PDT 2007
Hi all,
I had a doubt about syntactic predicates
I am sorry if i am asking a often repeated question .
I searched on the net and it did not help .
suppose i do this antlr2 it works perfectly fine .
<code>
protected NotIdType :~('a'..'z'| 'A'..'Z' | '_' | '0'..'9') ;
HEX_BIN_DEC:
( HEX H ) => (HEX H) { $setType(HEX); } //now HEX token will be
assigined to 1234H
| ( BIN B ) => (BIN B) { $setType(BIN); } //now BIN token will be
assigined to 1010B
| ( DEC D ) => (DEC D) { $setType(DEC); } //now DEC token will be
assigined to 1234D
| ( DEC NotIdType )=> DEC { $setType(DEC); } //now DEC token will
be assigined to //1234
</code>
i change this to antlr 3 grammar
<code>
fragment NotIdType :~('a'..'z'| 'A'..'Z' | '_' | '0'..'9') ;
HEX_BIN_DEC:// to resolve the ambiguity b/w bases
(HEX H) => (HEX H) { $type=(HEX); } //now HEX token will be
assigined to 1234H
| ( BIN B ) => ( BIN B ) { $type=(BIN); } //now BIN token will
be assigined to 1010B
| ( DEC D ) => ( DEC D ) { $type=(DEC); } //now DEC token will
be assigined to 1234D
| ( DEC NotIdType )=> (DEC) { $type=(DEC); } //now DEC token will
be assigined to 1234
</code>
this does not work fine as in
1234a will still be assigned DEC token due to the rule
( DEC NotIdType )=> (DEC){$type=(DEC);} //now DEC token will be
assigined to 1234
but this should not be so accotding to antlr 2
Please tell me what changes i need to make in the grammar to do the
same in antlr 3
Chintan Rao H
More information about the antlr-interest
mailing list