Add values to an ANTLR grammar

Asked

Viewed 17 times

1

I have a grammar:

    grammar SimpleCalc;

expr : term ( ( '+' | '-' ) term )* ';' ;
term : number ;
number  : DIGIT+ ;  
DIGIT : '0'..'9' ;
WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ -> channel(HIDDEN);

Exit:

    Parse Tree:
expr (
 term (
  number (
   "3"
  )
 )
 "+"
 term (
  number (
   "2"
  )
 )
 ";"
)

To add multiplication and division, would just do that?

expr : term ( ( '+' | '-' ) term )* ';' ;

I’m a little lost, if you have some doc to help me would be great

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.