[antlr-interest] C# target doesn't do numbers

Wincent Colaiuta win at wincent.com
Wed Jun 27 03:02:50 PDT 2007


El 27/6/2007, a las 11:19, Vaclav Barta escribió:

> constant returns [ ITerm value ] :
> 	Integer { $value = new IntegerValue(int.Parse($Integer.text)); }
> 	| NULL { $value = new NullValue(); }
> 	;
>
> NULL : 'null' ;
>
> Digit : '0'..'9' ;
>
> Integer : ( Digit )+ ;
>
> Whitespace : ( '\t' | ' ' | '\r' | '\n' )+ 	{ $channel = HIDDEN; }
> 	;
>
> (MacroScope.IntegerValue and MacroScope.NullValue are my classes  
> derived from MacroScope.ITerm.) ANTLWorks 1.0.2 considers this OK,  
> org.antlr.Tool from that jar generates lexer and parser from it  
> without complaints and Visual Studio 2005 compiles OK. But, when I run
>
> MacroScopeLexer lexer = new MacroScopeLexer(
> 	new ANTLRStringStream("1"));
> MacroScopeParser parser = new MacroScopeParser(
> 	new CommonTokenStream(lexer));
> return parser.constant();
>
> I get
>
> line 1:0 no viable alternative at input '1'


Have you tried making Digit a fragment rule? seeing as it is not  
referenced by any parser rule.

Cheers,
Wincent



More information about the antlr-interest mailing list