[antlr-interest] Re: Why is this nondeterministic?

danfuzz danfuzz at milk.com
Mon May 27 14:59:46 PDT 2002


Terence writes:
>The problem is that 'a' 'b' can start both REGULAR (via REGULAR_BIT) 
>and SPECIAL.  The lexer, given "ab" input would not know which token 
>to make.  This is an ambiguous grammar, which implies that it is 
>also nondeterministic.

Thanks for the quick reply. I'm still confused, though. I thought I
defined things such that REGULAR *can't* start with 'a' 'b'
(given that REGULAR_BIT matches 'a' 'a' and 'a' 'c' but not
'a' 'b').

My intent is for the lexer to return alternating tokens of
REGULAR or SPECIAL, where the text of REGULAR is a run of 'b's and 
'c's interspersed with "aa" and "ac" pairs (that is, 
"(b|c|aa|ac)*" in regex terms), and where the text of SPECIAL is 
always "ab".

Is it possible to say this with ANTLR? I noticed that, without
REGULAR being a closure (that is, saying just "REGULAR: 
REGULAR_BIT;") that the grammar compiles without complaint, so my
current workaround is to accumulate the REGULAR string  outside the 
lexer.

-dan

#####

Recap:

REGULAR: (REGULAR_BIT)+;
SPECIAL: 'a' 'b';

protected
REGULAR_BIT:
    ('b' | 'c')
|   ('a' 'a')
|   ('a' 'c')
;


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list