[antlr-interest] V3 -- No start rule??? (newbie question)

Terence Parr parrt at cs.usfca.edu
Sat Dec 16 18:37:07 PST 2006


that might actually work, but antlr is complaining that it does not  
know whether EOF can follow expr; it cannot find a rule not  
referenced by anybody else. For the life of me, I can't remember why  
I absolutely needed this to be an error inside the analysis. ;)

Ter
On Dec 16, 2006, at 6:29 PM, Bill Mayfield wrote:

> Howdy,
>
> I'm new to this. Any help is very much appreciated!
>
>
> How comes I get the following grammar error on the grammar below?
>
> ---------------
> error(138): SimpleCalc.g:0:0: grammar SimpleCalc: no start rule (no  
> rule can obviously be followed by EOF)
> ---------------
>
>
>
> = GRAMMAR  
> ====================================================================== 
> ====
>
>
>
> grammar SimpleCalc;
>
> options {
>    language=CSharp;
> }
>
> tokens {
>    PLUS    = '+' ;
>    MINUS    = '-' ;
>    MULT    = '*' ;
>    DIV    = '/' ;
> }
>
> @members {
>    public static void Main(string[] args) {
>        SimpleCalcLexer lex = new SimpleCalcLexer(new ANTLRFileStream 
> (args[0]));
>           CommonTokenStream tokens = new CommonTokenStream(lex);
>
>        SimpleCalcParser parser = new SimpleCalcParser(tokens);
>
>        try {
>            parser.expr();
>        } catch (RecognitionException e)  {
>            Console.Error.WriteLine(e.StackTrace);
>        }
>    }
> }
>
> /*------------------------------------------------------------------
> * PARSER RULES
> *------------------------------------------------------------------*/
>
> expr    : term ( ( PLUS | MINUS )  term )* ;
>    term    : factor ( ( MULT | DIV ) factor )* ;
>    factor    : NUMBER
>    | '(' expr ')' ;
>
>
> /*------------------------------------------------------------------
> * LEXER RULES
> *------------------------------------------------------------------*/
>
> NUMBER    : (DIGIT)+ ;
>    WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+      
> { $channel = HIDDEN; } ;
>    fragment DIGIT    : '0'..'9' ;
>



More information about the antlr-interest mailing list