TrikkStar/ProgLangAssignments

add surface level stuff for arithmetic

Closed this issue · 0 comments

  • Add in parser.mly four new tokens, PLUS, MINUS, TIMES, DIVIDE.
  • We next need to set up precedence rules. Place at the bottom of the current list, below the %nonassoc NOT, a line %left PLUS MINUS, and below that line add %left TIMES DIVIDE. This will ensure that all operations are performed in a left-associative way, and that multiplication and division will have higher precedence than addition and subtraction. This will agree with normal algebra rules.
  • Add expr cases at the bottom of parser.mly for expr PLUS expr and similarly for the other operations. They should all convert to the appropriate ArithS expression.
  • Add in lexer.mll near the bottom rules for "+", "-" and so on, to be converted to the corresponding tokens PLUS, MINUS and so on. Remember that the last two rules there about eof and any are catchalls and need to be the last cases.