diff --git a/table.c b/table.c index 8f11416..4469232 100644 --- a/table.c +++ b/table.c @@ -2,6 +2,7 @@ #include #include +int memorySizes[2] = {1,1}; /*At the start of the execution : the whole array is empty*/ static Symbol* symbolTable; @@ -85,8 +86,8 @@ void clearOutOfScopeVariable(){ } -/* Toggles the init state of the symbol */ -void toggleInit(char *name){ +/* sets the init state of the symbol to true */ +void setInit(char *name){ symbolTable[getIndex(name)].init = true; } diff --git a/table.h b/table.h index 4fb17c4..96aa89b 100644 --- a/table.h +++ b/table.h @@ -12,7 +12,7 @@ typedef enum enumVarType {INT, FLOAT} enumVarType; // a list of all type's sizes -extern int memorySizes[2] = {1,1}; // TODO : PROBLEM DOES'NT COMPILE +extern int memorySizes[2]; // TODO : PROBLEM DOES'NT COMPILE typedef struct { char name[NAME_MAX_LENGTH]; @@ -56,8 +56,8 @@ Symbol createNewStructure(char* name, enumVarType type); Element Edition ============================*/ -/* Toggles the init state of the symbol */ -void toggleInit(char *name); +/* sets the init state of the symbol to true */ +void setInit(char *name); /*============================ Element Access @@ -91,4 +91,8 @@ void error(char* mess); void line(); void doubleLine(); +/*displays the entire table at this moment including all information + * regarding the symbols and the current depth*/ +void displayTable(); + #endif diff --git a/testFile b/testFile index d3c3dba..3dad2fd 100644 --- a/testFile +++ b/testFile @@ -1,4 +1,6 @@ int compute(int a, int d) { + int b; + int c; b = a; while (c > 0) { b = b + a * 4; diff --git a/yacc.y b/yacc.y index c07c632..63165c1 100644 --- a/yacc.y +++ b/yacc.y @@ -11,8 +11,8 @@ void yyerror (const char *); } -// TODO : PROBLEM DOES'NT COMPILE (enumVarType doenst exist) -%union {int nbInt; enumVarType int type; char* string;} +// TODO : PROBLEM DOES'NT COMPILE (enumVarType doesn't exist) +%union {int nbInt; /*enumVarType*/ int type; char* string;} /*loops keywords*/ %token tWHILE tIF tELSE /*reserved keywords*/ @@ -91,7 +91,7 @@ IfStatement : tIF Condition InnerBlock WhileStatement : tWHILE Condition InnerBlock; -Assignment : tID tASSIGN Expression tSEMI {toggleInit($1);}; +Assignment : tID tASSIGN Expression tSEMI {setInit($1);}; /*Expression operation applied on variables or values*/ Expression : NbOrVariable @@ -125,11 +125,11 @@ VarsWithType : VarWithType VarWithType : Type tID; /*the return type or argument type*/ -Type : tINT {$$ = INT;} - | tFLOAT {$$ = FLOAT;}; +Type : tINT {$$ = /*INT*/ 0;} + | tFLOAT {$$ = /*FLOAT*/ 1;}; -Declaration : Type tID tSEMI {addElement($2, $1);} - | Type tID tASSIGN Expression tSEMI {addElement($2, $1);toggleInit($2);} +Declaration : Type tID tSEMI {addElement($2, (enumVarType) $1);} + | Type tID tASSIGN Expression tSEMI {addElement($2, $1);setInit($2);} /* Potential improvement : take care of multiple definition on same line*/ | Type tID tCOMMA VarsCommaSeparated tSEMI {yyerror("[Beta] you cannot -still- define several variable on the same line");}