[antlr-interest] please help on simple parser antlr v3

Michiel Vermandel Michiel_Vermandel at axi.be
Wed Sep 27 05:25:32 PDT 2006


Hi,

I started converting my v2 grammars to v3 and ran against some warnings 
when generating code for a very simple test grammar.
Below, you find the parser, followed by the warnings.
This grammar is a part of a grammar in v2 which I am converting.

In v2 the rule QUOTED_STRING was:

QUOTED_STRING: '\'' ( WS | '\'' '\'' | ~('\'') )* '\''; 

Now in v3 I get this list of warnings (see below).
In v2 the WS was needed in the QUOTED_STRING rule in order to increment 
the line counter properly.
I think I can solve the warnings by leaving out the WS rule since in Antlr 
v3 I do not need to bother about incrementing the line counter.

So, Can please someone confirm that I am right in just leaving out the WS 
rule from the QUOTED_STRING rule?

Thanks!


---------------------------------------------------------------------


grammar TestParser;
options {k=2; backtrack=true; memoize=true;}


statement: identifier | quoted_string ;

identifier:      IDENTIFIER;
 
quoted_string: QUOTED_STRING;


fragment
AZ_CHAR: 'a' .. 'z' | 'ç' | 'é' | 'è'| 'ê'  | 'à';

fragment
SPECIAL_CHAR: '_' | '$' | '#' ;

fragment
ANY_CHAR: AZ_CHAR | SPECIAL_CHAR;

IDENTIFIER:  ( AZ_CHAR | (N)+)  ANY_CHAR  (ANY_CHAR | N)*;
 
N:  ('0' .. '9')+;

WS      :       (' '
                |       '\t'
                |       ('\n'|'\r'('\n')?)
                )+
        { channel=99; };
 
QUOTED_STRING: '\'' ( WS | '\'' '\'' | ~('\'') )* '\''; 

-------------------------------------------------------------------------------

[14:09:37] test1.g:28:15: Decision can match input such as "'\n'" using 
multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
[14:09:37] test1.g:32:48: Decision can match input such as "' '" using 
multiple alternatives: 1, 3
As a result, alternative(s) 3 were disabled for that input
[14:09:37] test1.g:32:48: Decision can match input such as "'\t'" using 
multiple alternatives: 1, 3
As a result, alternative(s) 3 were disabled for that input
[14:09:37] test1.g:32:48: Decision can match input such as "'\r'" using 
multiple alternatives: 1, 3
As a result, alternative(s) 3 were disabled for that input
[14:09:37] test1.g:32:48: Decision can match input such as "'\n'" using 
multiple alternatives: 1, 3
As a result, alternative(s) 3 were disabled for that input
[14:09:37] C:\Documents and Settings\mvrm\My 
Documents\Antlr\grammars\test1.g:28:15: Decision can match input such as 
"'\n'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
[14:09:37] C:\Documents and Settings\mvrm\My 
Documents\Antlr\grammars\test1.g:32:48: Decision can match input such as 
"' '" using multiple alternatives: 1, 3
As a result, alternative(s) 3 were disabled for that input
[14:09:37] C:\Documents and Settings\mvrm\My 
Documents\Antlr\grammars\test1.g:32:48: Decision can match input such as 
"'\t'" using multiple alternatives: 1, 3
As a result, alternative(s) 3 were disabled for that input
[14:09:37] C:\Documents and Settings\mvrm\My 
Documents\Antlr\grammars\test1.g:32:48: Decision can match input such as 
"'\r'" using multiple alternatives: 1, 3
As a result, alternative(s) 3 were disabled for that input
[14:09:37] C:\Documents and Settings\mvrm\My 
Documents\Antlr\grammars\test1.g:32:48: Decision can match input such as 
"'\n'" using multiple alternatives: 1, 3
As a result, alternative(s) 3 were disabled for that input 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060927/9d5e39f7/attachment.html 


More information about the antlr-interest mailing list