I found a simple grammar to start learning ANTLR. I put it in the myGrammar.g file. here is the grammar:
grammar myGrammar;
/* This will be the entry point of our parser. */
eval
: additionExp
;
/* Addition and subtraction have the lowest precedence. */
additionExp
: multiplyExp
( '+' multiplyExp
| '-' multiplyExp
)*
;
/* Multiplication and division have a higher precedence. */
multiplyExp
: atomExp
( '*' atomExp
| '/' atomExp
)*
;
atomExp
: Number
| '(' additionExp ')'
;
/* A number: can be an integer value, or a decimal value */
Number
: ('0'..'9')+ ('.' ('0'..'9')+)?
;
/* We're going to ignore all white space characters */
WS
: (' ' | '\t' | '\r'| '\n') {$channel=HIDDEN;}
;
when I use this command :
java -jar /usr/local/...(antlr path) /home/ali/Destop/...(myGrammar.g path)
I have this error:
myGrammar.g:39:36: attribute references not allowed in lexer actions: $channel
what is the problem and what should I do?