Browse Source

Fix long additon

Ex : "1 + 2 + 4 ="
DricomDragon 5 years ago
parent
commit
88f70f1044
1 changed files with 5 additions and 9 deletions
  1. 5 9
      eval.y

+ 5 - 9
eval.y

@@ -31,17 +31,13 @@ EXPR_CALCS	: EXPR_CALC
 EXPR_CALC	: EXPR '=' 	{ printf("%d\n", $1); }
 		;
 
-EXPR	: TERM
-	| EXPR '+' TERM		{$$ = $1 + $3;}
-	| EXPR '-' TERM		{$$ = $1 - $3;}
+EXPR	: EXPR '+' EXPR		{$$ = $1 + $3;}
+	| EXPR '-' EXPR		{$$ = $1 - $3;}
+	| FACTOR
 	;
 
-TERM	: FACTOR
-	;
-
-FACTOR	:
-	| nombre		{$$ = $1;}
-	| EXPR '*' TERM		{$$ = $1 * $3;}
+FACTOR	: nombre		{$$ = $1;}
+	| FACTOR '*' FACTOR	{$$ = $1 * $3;}
 	| '(' EXPR ')'		{$$ = $2;}
 	;