grammar SimpleCalc;
options
{
language=C;
}
tokens
{
PLUS = '+' ;
MINUS = '-' ;
MULT = '*' ;
DIV = '/' ;
}
@members
{
#include "SimpleCalcLexer.h"
int main(int argc, char * argv[])
{
pANTLR3_INPUT_STREAM { input;
pSimpleCalcLexer #include "SimpleCalcLexer.h" lex;
pANTLR3_COMMON_TOKEN_STREAM tokens;
pSimpleCalcParser pANTLR3_INPUT_STREAM input = antlr3AsciiFileStreamNew(argv[1]); parser;
input = antlr3AsciiFileStreamNew pSimpleCalcLexer lex = SimpleCalcLexerNew(inputargv[1]);
lex = SimpleCalcLexerNew pANTLR3_COMMON_TOKEN_STREAM (input);
tokens = antlr3CommonTokenStreamSourceNew (ANTLR3_SIZE_HINT, lex->pLexer->tokSourceTOKENSOURCE(lex));
parser = SimpleCalcParserNew pSimpleCalcParser parser = SimpleCalcParserNew(tokens);
parser parser->expr(parser);
// Must manually clean up
//
parser ->free(parser);
tokens parser->free(parsertokens);
lex tokens->free(tokens);
lex->free(lex);
input input->close(input);
return 0;
}
}
}
/*------------------------------------------------------------------
* PARSER RULES
*------------------------------------------------------------------*/
expr : term ( ( PLUS | MINUS ) term )*
;
term : factor ( ( MULT | DIV ) factor )*
;
factor : NUMBER
;
/*------------------------------------------------------------------
* LEXER RULES
*------------------------------------------------------------------*/
NUMBER : (DIGIT)+)+
;
WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+
{
$channel = HIDDEN;
}
;
fragment
DIGIT : '0'..'9'
;
|