parsing - ANTLR won't parse this easy input for simple calculator grammar -
grammar testcsharpparser; options { language=csharp3; } @parser::namespace { demo.antlr } @lexer::namespace { demo.antlr } parse returns [double value] : exp eof {$value = $exp.value;} ; exp returns [double value] : addexp {$value = $addexp.value;} ; addexp returns [double value] : a=mulexp {$value = $a.value;} ( '+' b=mulexp {$value += $b.value;} | '-' b=mulexp {$value -= $b.value;} )* ; mulexp returns [double value] : a=unaryexp {$value = $a.value;} ( '*' b=unaryexp {$value *= $b.value;} | '/' b=unaryexp {$value /= $b.value;} )* ; unaryexp returns [double value] : '-' atom {$value = -1.0 * $atom.value;} | atom {$value = $atom.value;} ; atom returns [double value] : number {$value = double.parse($number.text, cultureinfo.invariantculture);} | '(' exp ')' {$value = $exp.value;} ; number : ('0'..'9')+ ('.' ('0'..'9')+)? ; space : (' ' | '\t' | '\r' | '\n'){$channel = hidden;} ;
the grammar won't parse simple statement 4/5
or (4/5)
tried using antlrworks.
does have idea why happening? mind should work correctly.
it keeps giving me noviablealtexception
.
i see several problems related use of csharp3 target.
- the csharp2 , csharp3 targets define constant
hidden
instead ofhidden
- antlrworks cannot used generate parsers grammars targeting csharp2 or csharp3 targets. parser must generated either msbuild (preferred) or using antlr3.exe. these documented on antlr 3 c# releases wiki page.
- antlrworks cannot used test parsers generated csharp2 or csharp3 targets. results reported interpreter or debugger cannot trusted.
Comments
Post a Comment