Browse Source

Implement priority for multiplication

DricomDragon 5 years ago
parent
commit
9594b188c8
1 changed files with 20 additions and 16 deletions
  1. 20 16
      eval.y

+ 20 - 16
eval.y

@@ -24,22 +24,26 @@ extern char* yytext;
 
 %%
 
-EXPR_CALCS : EXPR_CALC              
-           | EXPR_CALCS EXPR_CALC   
-           ;
-
-EXPR_CALC : EXPR '='		{ printf("%d\n", $1); }
-          ;
-
-EXPR     : TERM
-         | EXPR '+' TERM	{$$ = $1 + $3;}
-         | EXPR '-' TERM	{$$ = $1 - $3;}
-	 | EXPR '*' TERM	{$$ = $1 * $3;}
-         ;
-
-TERM  : nombre			{$$ = $1;}
-         | '(' EXPR ')'		{$$ = $2;}
-         ;
+EXPR_CALCS	: EXPR_CALC
+		| EXPR_CALCS EXPR_CALC
+		;
+
+EXPR_CALC	: EXPR '=' 	{ printf("%d\n", $1); }
+		;
+
+EXPR	: TERM
+	| EXPR '+' TERM		{$$ = $1 + $3;}
+	| EXPR '-' TERM		{$$ = $1 - $3;}
+	;
+
+TERM	: FACTOR
+	;
+
+FACTOR	:
+	| nombre		{$$ = $1;}
+	| EXPR '*' TERM		{$$ = $1 * $3;}
+	| '(' EXPR ')'		{$$ = $2;}
+	;
 
 %%
 #include <stdio.h>