Browse Source

Fix the left priority for division

Fix the shift/reduce problem caused by rules associated with FACTOR token
DricomDragon 5 years ago
parent
commit
516d6306a6
1 changed files with 7 additions and 4 deletions
  1. 7 4
      eval.y

+ 7 - 4
eval.y

@@ -34,12 +34,15 @@ EXPR	: EXPR '+' FACTOR	{$$ = $1 + $3;}
         | FACTOR
 	;
 
-FACTOR	: number		{$$ = $1;}
-	| FACTOR '*' FACTOR	{$$ = $1 * $3;}
-	| FACTOR '/' FACTOR	{$$ = $1 / $3;}
-	| '(' EXPR ')'		{$$ = $2;}
+FACTOR	: FACTOR '*' ATOM	{$$ = $1 * $3;}
+	| FACTOR '/' ATOM	{$$ = $1 / $3;}
+        | ATOM
 	;
 
+ATOM    : number                {$$ = $1;}
+	| '(' EXPR ')'		{$$ = $2;}
+        ;
+
 %%
 #include <stdio.h>
 #include "eval.tab.h"