Update parser and lexer for comparisons
Closed this issue · 0 comments
TrikkStar commented
- Add a new token called COMPOP that contains a string in it. Model it after the FLOAT token.
- Place %nonassoc COMPOP between the %nonassoc NOT and %left PLUS MINUS lines. This should make arithmetic happen first, but comparison right after that, before logical operators are taken into account. So something like 3 < 4 and 1 < 2 would behave properly.
- Add | expr COMPOP expr { CompS ($2, $1, $3) } as a case in the expr rule in parser.mly.
- In lexer.mll, add a new binding let comp = ">" | ">=" | "<" | "<=", then further down a new rule | comp as s { COMPOP s }. This recognizes the above four operators and stores the match as part of the COMPOP token.