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

Bill Mayfield antlr at telenet.be
Sat Dec 16 18:29:43 PST 2006


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