From: Siraaj Khandkar Date: Wed, 30 May 2018 02:35:46 +0000 (-0400) Subject: Fix the remaining 12 shift/reduce conflicts X-Git-Url: https://git.xandkar.net/?p=tiger.ml.git;a=commitdiff_plain;h=6a74bf44cae52e2d56f58730e46a71eb9d4ba0c8 Fix the remaining 12 shift/reduce conflicts which were due to associativity and precedence conflicts between operators, previously defined as a single production --- diff --git a/tiger/src/lib/tiger/tiger_parser.mly b/tiger/src/lib/tiger/tiger_parser.mly index 610ea48..1bc0ae7 100644 --- a/tiger/src/lib/tiger/tiger_parser.mly +++ b/tiger/src/lib/tiger/tiger_parser.mly @@ -127,9 +127,53 @@ exp: let fun_args = $3 in sprintf "fun_call[%s, %s]" id fun_args } - | exp op exp + | exp PLUS exp { - sprintf "op[%s %s %s]" $1 $2 $3 + sprintf "op_plus[%s + %s]" $1 $3 + } + | exp MINUS exp + { + sprintf "op_minus[%s - %s]" $1 $3 + } + | exp TIMES exp + { + sprintf "op_times[%s * %s]" $1 $3 + } + | exp DIVIDE exp + { + sprintf "op_divide[%s / %s]" $1 $3 + } + | exp EQ exp + { + sprintf "op_eq[%s = %s]" $1 $3 + } + | exp NEQ exp + { + sprintf "op_neq[%s <> %s]" $1 $3 + } + | exp GT exp + { + sprintf "op_gt[%s > %s]" $1 $3 + } + | exp LT exp + { + sprintf "op_lt[%s < %s]" $1 $3 + } + | exp GE exp + { + sprintf "op_ge[%s >= %s]" $1 $3 + } + | exp LE exp + { + sprintf "op_le[%s <= %s]" $1 $3 + } + | exp AND exp + { + sprintf "op_and[%s & %s]" $1 $3 + } + | exp OR exp + { + sprintf "op_or[%s | %s]" $1 $3 } | IF exp THEN exp ELSE exp { @@ -311,21 +355,6 @@ fun_args: } ; -op: - | PLUS {"+"} - | MINUS {"-"} - | TIMES {"*"} - | DIVIDE {"/"} - | EQ {"="} - | NEQ {"<>"} - | GT {">"} - | LT {"<"} - | GE {">="} - | LE {"<="} - | AND {"&"} - | OR {"|"} - ; - lvalue: | ID lvalue_part {