%union { int nombre; char id[30]; } %{ #include #include "table_symboles.h" enum Initialised_Variable init; enum Symbole_Type type; Table_Symboles table; %} %token tENTIER %token tENTIEREXP %token tADD %token tSUB %token tMUL %token tDIV %token tPO %token tPF %token tAO %token tAF %token tERROR %token tPV %token tVIRGULE %token tAFFECTATION %token tEGAL %token tDIFF %token tLT %token tGT %token tGTE %token tLTE %token tMAIN %token tINT %token tPRINT %token tRETURN %token tOR %token tAND %token tIF %token tELSE %token tWHILE %token tCONST %token tVAR %token tNOT %left tADD %left tSUB %left tMUL %left tDIV %right tEGAL %% //C : Fonctions Main ; //Fonctions : Fonction Fonctions | ; //Fonction : tINT tVAR tPO Params tPF Body; Main : tINT tMAIN tPO Params tPF Body {}; Params : {printf("Sans params\n");} ; Params : Param SuiteParams ; Param : tINT tVAR {printf("Parametre : %s\n", $2);} ; SuiteParams : tVIRGULE Param SuiteParams tPV ; SuiteParams : ; Body : tAO Instructions Return tAF {printf("Dans body\n");} ; Instructions : Instruction Instructions ; Instructions : ; Instruction : Aff ; Instruction : If ; Instruction : While ; Instruction : Print ; Instruction : Decl ; Instruction : Invocation tPV ; Decl : Type Valeur SuiteDecl tPV ; SuiteDecl: tVIRGULE Valeur SuiteDecl ; SuiteDecl: ; Type : tINT {type = TYPE_INT;} ; Type : tCONST tINT {type = TYPE_CONST_INT;} ; Valeur : tVAR tAFFECTATION E {add_symbole_top(&table, $1, type, INITIALISED, table.depth);}; Valeur : tVAR {add_symbole_top(&table, $1, type, NOT_INITIALISED, table.depth);}; Aff : tVAR tAFFECTATION E tPV {printf("Affectation : %s\n", $1);}; E : tENTIER {printf("int %d\n", $1);}; E : tVAR {printf("var %s\n", $1);}; E : E tADD E {printf("Addition\n");} ; E : E tMUL E {printf("Multiplication\n");} ; E : E tSUB E {printf("Soustraction\n");} ; E : E tDIV E {printf("Division\n");} ; E : tSUB E {printf("Soustraction\n");} ; E : Invocation ; E : tPO E tPF {printf("Parenthèse\n");} ; Args : tVAR SuiteArgs ; Args : ; SuiteArgs : tVIRGULE tVAR SuiteArgs ; SuiteArgs : ; If : tIF tPO Cond tPF tAO Instructions tAF Else {printf("Dans if\n");}; Else : tELSE tAO Instructions tAF {printf("else\n");} ; Else : tELSE tIF tPO Cond tPF tAO Instructions tAF Else {printf("elsif\n");} ; While : tWHILE tPO Cond tPF tAO Instructions tAF {printf("Dans while\n");}; Cond : E tEGAL E {printf("Cond ==\n");} ; Cond : E tDIFF E {printf("Cond !=\n");} ; Cond : E tLT E {printf("Cond <\n");} ; Cond : E tGT E {printf("Cond >\n");} ; Cond : E tLTE E {printf("Cond <=\n");} ; Cond : E tGTE E{printf("Cond >=\n");} ; Cond : E tAND Cond {printf("Cond &&\n");} ; Cond : E tOR Cond {printf("Cond ||\n");} ; Cond : tNOT Cond {printf("Cond !\n");} ; Invocation : tVAR tPO Args tPF {printf("Dans invocation\n");}; Print : tPRINT tPO tVAR tPF tPV {printf("printf de %s\n", $3);}; Return : tRETURN E tPV {printf("return\n");}; %% #include void main(void){ //TODO: rajouter gestion des erreurs initialise_table(&table); yyparse(); print_table(&table); remove_symboles(&table, 0); print_table(&table); }