fixed last bugs

This commit is contained in:
Raphaël LACROIX 2023-04-13 11:11:16 +02:00
parent 6bbc6c2d30
commit 9439274586
2 changed files with 7 additions and 4 deletions

View file

@ -9,7 +9,7 @@ int compute(int a, int d) {
} }
void main(void) { void main(int a) {
int a; int a;
if (a == 3) { if (a == 3) {
print(a); print(a);

9
yacc.y
View file

@ -1,3 +1,5 @@
%define parse.error detailed
%{ %{
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -108,7 +110,8 @@ Expressions : Expression
FunctionCall : tID tLPAR Expressions tRPAR; FunctionCall : tID tLPAR Expressions tRPAR;
FunctionDef : Type tID FunctionParams InnerBlock; FunctionDef : Type tID FunctionParams InnerBlock
| tVOID tID FunctionParams InnerBlock;
/*FunctionParams = the parameters of a function*/ /*FunctionParams = the parameters of a function*/
FunctionParams : tLPAR tRPAR FunctionParams : tLPAR tRPAR
@ -122,8 +125,8 @@ VarsWithType : VarWithType
VarWithType : Type tID; VarWithType : Type tID;
/*the return type or argument type*/ /*the return type or argument type*/
Type : tINT {$$ = /*INT*/ 0;} Type : tINT {$$ = INT;}
| tFLOAT {$$ = /*FLOAT*/ 1;}; | tFLOAT {$$ = FLOAT;};
Declaration : Type tID tSEMI {addElement($2, (enumVarType) $1);} Declaration : Type tID tSEMI {addElement($2, (enumVarType) $1);}
| Type tID tASSIGN Expression tSEMI {addElement($2, $1);setInit($2);} | Type tID tASSIGN Expression tSEMI {addElement($2, $1);setInit($2);}