This commit is contained in:
Raphaël LACROIX 2023-04-13 10:03:02 +02:00
parent 1a3d71e8bf
commit 1a8e9766a0
4 changed files with 19 additions and 12 deletions

View file

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
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;
}

10
table.h
View file

@ -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

View file

@ -1,4 +1,6 @@
int compute(int a, int d) {
int b;
int c;
b = a;
while (c > 0) {
b = b + a * 4;

14
yacc.y
View file

@ -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");}