[antlr-interest] C# target doesn't do numbers
Vaclav Barta
vbar at comp.cz
Wed Jun 27 02:19:43 PDT 2007
Hi,
I'm trying to construct an ANTL grammar for SQL queries (based on
http://www.antlr.org/grammar/1062280680642/MS_SQL_SELECT.html, except it
should be some SQL subset acceptable to multiple SQL engines), and I
have trouble parsing expressions. I've simplified the grammar to the bone:
grammar MacroScope;
options
{
language=CSharp;
}
@lexer::namespace
{
MacroScope
}
@parser::namespace
{
MacroScope
}
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'
on standard output (something I'll need to turn off, but first things
first) and parser.constant() returns null. I have a feeling I'm missing
something very obvious... Any suggestions?
Bye
Vasek
More information about the antlr-interest
mailing list