key-word limitations
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   David_Brumley
Posted On:   Friday, July 11, 2003 02:42 PM

Does ANTLR impose keyword restrictions in the parser? For example, it seems I can specify: class MyParser extends Parser; list: |ID {/* reduce 0 */ } |"readonly" { /* reduce 1 */ } |"read-only" {/* reduce 2 */ } ; class MyLexer extends Lexer; ID options {testLiterals=true; }: ('a'..'z')+; If I run the parser w/ input "readonly", then reduce1 is executed. However, with "read-only" reduce0 is executed, not reduce 2. When I look at MyParserTokenTypes.java, I see: int LITERAL_readonly = 6; // "read-only" = 7 i.e. the literal "   More>>

Does ANTLR impose keyword restrictions in the parser?
For example, it seems I can specify:


			
class MyParser extends Parser;
list:
|ID {/* reduce 0 */ }
|"readonly" { /* reduce 1 */ }
|"read-only" {/* reduce 2 */ }
;


class MyLexer extends Lexer;
ID options {testLiterals=true; }: ('a'..'z')+;



If I run the parser w/ input "readonly", then reduce1 is executed. However, with "read-only" reduce0 is executed, not reduce 2.


When I look at MyParserTokenTypes.java, I see:

			
int LITERAL_readonly = 6;
// "read-only" = 7


i.e. the literal "read-only" is commented out.


Is this a bug, and can I get around it? thanks. david    <<Less

Re: key-word limitations

Posted By:   Terence_Parr  
Posted On:   Tuesday, July 15, 2003 09:14 AM

Hi. The problem is that ID can't match '-'. The lexer tests literals against all tokens that match to see if it should override it for a keyword. ID can't match it so it can't every do ""read-only"". :) Add '-' or have the keyword match another lexer rule. :)


Terence

About | Sitemap | Contact