- Joined
- Jul 10, 2007
- Messages
- 6,306
Code:
grammar Grammar;
import Operation;
firstrule: (assignment | function)*; //nothing
assignment: Identifier | array '=' expression; //onEnter, if var == Identifier, set map, otherwise set double map?
//visit expression with a visitor
expression: expression op=EXP<assoc=right> expression #OpExponent //return exponent, visit expression
| expression op=(MUL|DIV) expression #OpMulDiv //return mult or div, visit expression
| expression '(' expression ')' #OpExpressionMul1 //return mult, visit expression
| function #LFunction //visit function
| expression Identifier #OpExpressionMul2 //return mult, visit expression
| expression op=(ADD|SUB) expression #OpAddSub //return
| array #LArray //visit array
| Identifier #LIdentifier
| Integer #LInteger
| Float #LFloat
| '(' expression ')' #OpExpression
;
array: Identifier '[' expression ']'; //read value given expression, validate that the expression is an integer
argumentList: expression (',' expression)*;
function: Identifier '(' argumentList ')';
COMMENT: '//' ~[\r\n]* -> skip;
COMMENT_DELIMITED: '/*' .* '*/' -> skip;
Integer: '0' | ([1-9][0-9]*);
Float: ('0' | ([1-9][0-9]*)) ('.' [0-9]*)?;
Identifier: [a-zA-Z_][a-zA-Z0-9_]*;
WS: [ \t\r\n] -> skip;
Code:
lexer grammar Operation;
EXP: '**';
MUL: '*';
DIV: '/';
ADD: '+';
SUB: '-';
Last edited: