From 6a74bf44cae52e2d56f58730e46a71eb9d4ba0c8 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Tue, 29 May 2018 22:35:46 -0400 Subject: [PATCH] Fix the remaining 12 shift/reduce conflicts which were due to associativity and precedence conflicts between operators, previously defined as a single production --- tiger/src/lib/tiger/tiger_parser.mly | 63 ++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 17 deletions(-) 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 { -- 2.20.1