2009/12/9 Sam Harwell <[email protected]>
>
> Do you currently have the IDENTIFIER lexer rule located before (as in line 
> number) ABSTRACT, etc.? I'm guessing that's the cause of your current problem.

Hi Sam,
Thanks for the quick response.
Unfortunately no, my IDENTIFIER rule is the last non-fragment rule in
the grammar file.

>
> Also, don't specify a value for k in your lexer.
>

Ok, but it does not matter much in my case.

>
> On a side note, this really isn't the ANTLR way to do things, but your 
> generated code will be smaller and faster if you do this. I might have the 
> syntax slightly wrong since I'm not a Java programmer. If you are using a 
> combined grammar (lexer and parser in the same file), a downside of doing 
> this is you have to always use ABSTRACT in the parser rules, where normally 
> 'abstract' would alias itself to the token.
>
> @lexer
> {
> Hashtable<String, Integer> keywords = new Hashtable()
>    {{
>    put("abstract", ABSTRACT);
>    put("break", BREAK);
>    }};
> }
>
> // the fragment rules assign values to the token types that you can use in 
> the parser.
> fragment ABSTRACT : ;
> fragment BREAK : ;
>
> IDENTIFIER
> @after
> {
> Integer value = keywords.get($text);
> if (value != null)
>    setType(value); // might be state.setType
> }
>    : ...
>    ;


Interesting, that might work. I'll try this soon. But can you tell me
why my original example is wrong? If I understand ANTLR correctly this
should not pose any problems for LL(*)

--
Greetings
Marcin Rzeźnicki

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

--

You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.


Reply via email to