[antlr-interest] Interpretation of Parser Rule w/ Alternative Lexer RHS

Kay Roepke kroepke at classdump.org
Sun Nov 12 17:49:30 PST 2006


Hi Randall!

On 13. Nov 2006, at 2:37 , Randall R Schulz wrote:

> When I look at this rule in ANTLRworks Syntax Diagram view, it shows:
>
>     +--------------------------+
> ----|LowerWord..UnsignedInteger|---
>     +--------------------------+
>
> I know how to interpret 'a'..'z' in these diagrams (I think) but not
> this notation using lexer rule names.

All tokens get assigned a unique number (the token type). ANTLR uses  
these
internally to represent kinds of tokens (in switch, if, bitsets). If  
it turns
out that LowerWord < SingleQuoted < UnsignedInteger (i.e. their token  
types)
ANTLR represents a test for those as 'LowerWord..UnsignedInteger'.

Can be hard to read if you don't know the tokentypes, but they are  
both in the
generated code, as well as in the .tokens file.

> So I'm confused about how lexer rules are interpreted when reference
> from parser rules. How do I write a parser rule that can accept one of
> several lexeme types?

like you did. it should work, but the actual outcome may depend on  
other rules (i.e.
the lookahead).

> Can someone clarify this?

hard to say without seeing the grammar and sample input that fails to  
be recognized.
could you provide a more detailed example?

HTH,
-k

-- 
Kay Röpke
http://classdump.org/






More information about the antlr-interest mailing list