dcsimg
The eternal question: Why is this ambiguous??
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Friday, December 3, 2004 01:08 AM

I have already written a few ANTLR lexers and parsers (for productive systems, with sometimes weird grammars) - but the following puzzles me: Why does the following simple grammar create an ambiguous warning?: class MyLexer extends Lexer; options { charVocabulary = '3'..'377'; k=3; caseSensitive=false; } COMMENT_COMMAND : '-' '-' '$' ; SQL_STATEMENT : ( SYMBOL )+ ';' ; protected SYMBOL : ('-' (~ '-')) => '-' //1 | 'a' | '"' (~ '"')* '"' //2 ; When I remove either of //1 or //2, the ambiguity goes away.    More>>

I have already written a few ANTLR lexers and parsers (for productive systems, with sometimes weird grammars) - but the following puzzles me:


Why does the following simple grammar create an ambiguous warning?:


			
class MyLexer extends Lexer;

options {
charVocabulary = '3'..'377';
k=3;
caseSensitive=false;
}

COMMENT_COMMAND
: '-' '-' '$'
;

SQL_STATEMENT
: ( SYMBOL )+
';'
;

protected SYMBOL
: ('-' (~ '-')) => '-' //1
| 'a'
| '"' (~ '"')* '"' //2
;

When I remove either of //1 or //2, the ambiguity goes away.


When I replace //2 with

			
| '"' (~ ('"'|'$'))* '"'

- i.e., I also exclude $ inside the "string" -, the ambiguity also goes away.


But why would a $ after(!!) a " lead to an ambiguity?????


Thanks for any help!


Harald M.

   <<Less
About | Sitemap | Contact