|
@@ -10,7 +10,7 @@
|
10
|
10
|
#include "../Tables/Instructions/tab_instruc.h"
|
11
|
11
|
#define TAILLE 1024
|
12
|
12
|
|
13
|
|
-enum type_t type_courant;
|
|
13
|
+struct type_t type_courant;
|
14
|
14
|
|
15
|
15
|
int instructions_ligne_to_patch[10][20];
|
16
|
16
|
int nbs_instructions_to_patch[10];
|
|
@@ -31,6 +31,7 @@ int nbs_instructions_to_patch[10];
|
31
|
31
|
%token<nombre> tIF tWHILE tELSE
|
32
|
32
|
%token tLT tGT tEQCOND
|
33
|
33
|
%token tAND tOR
|
|
34
|
+%token tADDR
|
34
|
35
|
|
35
|
36
|
%left tAND tOR
|
36
|
37
|
%left tNOT
|
|
@@ -39,7 +40,7 @@ int nbs_instructions_to_patch[10];
|
39
|
40
|
%left tADD tSUB
|
40
|
41
|
%left tMUL tDIV
|
41
|
42
|
|
42
|
|
-%type<nombre> E Invocation
|
|
43
|
+%type<nombre> E Invocation DebutAff
|
43
|
44
|
|
44
|
45
|
|
45
|
46
|
|
|
@@ -53,11 +54,11 @@ Main : tINT tMAIN tOBRACE Params tCBRACE Body { print(); create_asm();} ;
|
53
|
54
|
|
54
|
55
|
Params : { printf("Sans Params\n"); } ;
|
55
|
56
|
Params : Param SuiteParams ;
|
56
|
|
-Param : DeclType tID { printf("Prametre : %s\n", $2); };
|
|
57
|
+Param : Type tID { printf("Prametre : %s\n", $2); };
|
57
|
58
|
SuiteParams : tCOMA Param SuiteParams ;
|
58
|
59
|
SuiteParams : ;
|
59
|
60
|
|
60
|
|
-Body : tOBRACKET Instructions tCBRACKET { } ;
|
|
61
|
+Body : tOBRACKET {profondeur++;} Instructions tCBRACKET {print(); reset_pronf(); profondeur--;} ;
|
61
|
62
|
|
62
|
63
|
|
63
|
64
|
Instructions : Instruction Instructions ;
|
|
@@ -69,29 +70,17 @@ Instruction : If {reset_temp_vars();};
|
69
|
70
|
Instruction : While {reset_temp_vars();};
|
70
|
71
|
|
71
|
72
|
//On considère que la première ligne du code en ASM est la ligne 0
|
72
|
|
-If : tIF tOBRACE E tCBRACE { profondeur++;
|
|
73
|
+If : tIF tOBRACE E tCBRACE {
|
73
|
74
|
add_operation(JMF,$3,0,0); $1 = get_current_index() - 1;}
|
74
|
75
|
Body {int current = get_current_index();
|
75
|
76
|
patch($1,current + 1);
|
76
|
77
|
add_operation(JMP,0,0,0);
|
77
|
78
|
instructions_ligne_to_patch[profondeur][nbs_instructions_to_patch[profondeur]] = current;
|
78
|
79
|
nbs_instructions_to_patch[profondeur]++;}
|
79
|
|
-Else { printf("If reconnu\n"); reset_pronf(); profondeur--;};
|
80
|
|
-
|
81
|
|
-
|
82
|
|
-//On considère que la première ligne du code en ASM est la ligne 0
|
83
|
|
-ElseIf : tIF tOBRACE E tCBRACE {add_operation(JMF,$3,0,0); $1 = get_current_index() - 1;}
|
84
|
|
-Body {int current = get_current_index();
|
85
|
|
- patch($1,current + 1);
|
86
|
|
- add_operation(JMP,0,0,0);
|
87
|
|
- instructions_ligne_to_patch[profondeur][nbs_instructions_to_patch[profondeur]] = current;
|
88
|
|
- nbs_instructions_to_patch[profondeur]++;}
|
89
|
80
|
Else { printf("If reconnu\n");};
|
90
|
81
|
|
91
|
82
|
|
92
|
|
-
|
93
|
|
-
|
94
|
|
-Else : tELSE ElseIf { printf("Else if reconnu\n"); };
|
|
83
|
+Else : tELSE If { printf("Else if reconnu\n"); };
|
95
|
84
|
Else : tELSE Body { printf("Else reconnu\n"); int current = get_current_index();
|
96
|
85
|
for (int i = 0; i< nbs_instructions_to_patch[profondeur]; i++){
|
97
|
86
|
patch(instructions_ligne_to_patch[profondeur][i],current);
|
|
@@ -103,44 +92,52 @@ for (int i = 0; i< nbs_instructions_to_patch[profondeur]; i++){
|
103
|
92
|
patch(instructions_ligne_to_patch[profondeur][i],current);
|
104
|
93
|
}
|
105
|
94
|
nbs_instructions_to_patch[profondeur] = 0;};
|
106
|
|
-While : tWHILE tOBRACE E tCBRACE {profondeur++;
|
|
95
|
+While : tWHILE tOBRACE E tCBRACE {
|
107
|
96
|
add_operation(JMF,$3,0,0);
|
108
|
97
|
$1 = get_current_index() - 1;}
|
109
|
98
|
|
110
|
99
|
Body { printf("While reconnu\n");
|
111
|
100
|
int current = get_current_index();
|
112
|
101
|
patch($1,current + 1);
|
113
|
|
-add_operation(JMP,$1,0,0);
|
114
|
|
-reset_pronf(); profondeur--;};
|
|
102
|
+add_operation(JMP,$1,0,0);};
|
|
103
|
+
|
115
|
104
|
|
|
105
|
+Aff : DebutAff tEQ E tPV {add_operation(COP, $1, $3,0);} ; //besoin de get_address
|
116
|
106
|
|
117
|
|
-Aff : tID tEQ E tPV { printf("%s prend une valeur\n", $1); struct symbole_t * symbole = get_variable($1); symbole->initialized = 1; add_operation(COP, symbole->adresse, $3,0);} ; //besoin de get_address
|
|
107
|
+DebutAff : tID {struct symbole_t * symbole = get_variable($1); symbole->initialized = 1; $$=symbole->adresse; printf("%s prend une valeur\n", $1);};
|
|
108
|
+DebutAff : tMUL E { add_operation(GET, $2, $2, 0); $$=$2;};
|
|
109
|
+DebutAff : tADDR tID { int addr = allocate_mem_temp_var(INT); struct symbole_t * symbole = get_variable($2); add_operation(AFC,addr, symbole->adresse,0); $$=addr;};
|
118
|
110
|
|
119
|
111
|
E : tNB { int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
120
|
112
|
|
121
|
113
|
E : tNBEXP { printf("Nombre exp\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
122
|
|
-E : tID { printf("Id\n"); struct symbole_t * symbole = get_variable($1); int addr = allocate_mem_temp_var(symbole->type); add_operation(COP, addr,symbole->adresse,0); $$=addr;};
|
123
|
|
-E : E tMUL E { printf("Mul\n"); int addr = allocate_mem_temp_var(INT); add_operation(MUL, addr,$1,$3); $$ = addr;};
|
124
|
|
-E : E tDIV E { printf("Div\n"); int addr = allocate_mem_temp_var(INT); add_operation(DIV, addr,$1,$3); $$ = addr;};
|
125
|
|
-E : E tSUB E { printf("Sub\n"); int addr = allocate_mem_temp_var(INT); add_operation(SOU, addr,$1,$3); $$ = addr;};
|
126
|
|
-E : E tADD E { printf("Add\n"); int addr = allocate_mem_temp_var(INT); add_operation(ADD, addr,$1,$3); $$ = addr;};
|
|
114
|
+E : tID { printf("Id\n"); struct symbole_t * symbole = get_variable($1); int addr = allocate_mem_temp_var(symbole->type.base); add_operation(COP, addr,symbole->adresse,0); $$=addr;};
|
|
115
|
+E : E tMUL E { printf("Mul\n"); add_operation(MUL,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
|
116
|
+E : E tDIV E { printf("Div\n"); add_operation(DIV, $1,$1,$3); $$ = $1; decrement_temp_var();};
|
|
117
|
+E : E tSUB E { printf("Sub\n"); add_operation(SOU,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
|
118
|
+E : E tADD E { printf("Add\n"); add_operation(ADD,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
127
|
119
|
E : Invocation { printf("Invoc\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
128
|
120
|
E : tOBRACE E tCBRACE { printf("Parentheses\n"); $$=$2;};
|
129
|
|
-E : tSUB E { printf("Moins\n"); int addr = allocate_mem_temp_var(INT); add_operation(SOU, 0,addr,0); $$ = addr;};
|
130
|
|
-E : E tEQCOND E { printf("==\n"); int addr = allocate_mem_temp_var(INT); add_operation(EQU, addr,$1,$3); $$ = addr;};
|
131
|
|
-E : E tGT E { printf(">\n"); int addr = allocate_mem_temp_var(INT); add_operation(SUP, addr,$1,$3); $$ = addr;};
|
132
|
|
-E : E tLT E { printf("<\n"); int addr = allocate_mem_temp_var(INT); add_operation(INF, addr,$1,$3); $$ = addr;};
|
|
121
|
+E : tSUB E { printf("Moins\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,0,0); add_operation(SOU, $2,$2,addr); $$ = $2; decrement_temp_var();};
|
|
122
|
+E : E tEQCOND E { printf("==\n"); add_operation(EQU,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
|
123
|
+E : E tGT E { printf(">\n"); add_operation(SUP,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
|
124
|
+E : E tLT E { printf("<\n"); add_operation(INF,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
133
|
125
|
E : tNOT E { printf("!\n"); };
|
134
|
|
-E : E tAND E {int addr = allocate_mem_temp_var(INT); add_operation(MUL, addr, $1, $3); $$=addr;};
|
135
|
|
-E : E tOR E {int addr = allocate_mem_temp_var(INT); add_operation(ADD, addr, $1, $3); $$=addr;} ;
|
|
126
|
+E : E tAND E {add_operation(MUL,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
|
127
|
+E : E tOR E {add_operation(ADD,$1,$1,$3); $$ = $1; decrement_temp_var();} ;
|
|
128
|
+E : tMUL E { add_operation(GET, $2, $2, 0); $$=$2;};
|
|
129
|
+E : tADDR tID { int addr = allocate_mem_temp_var(INT); struct symbole_t * symbole = get_variable($2); add_operation(AFC,addr, symbole->adresse,0); $$=addr;};
|
136
|
130
|
|
137
|
131
|
|
138
|
132
|
|
139
|
133
|
//Créer un champ isConst dans la table des symboles
|
140
|
|
-DeclType : tINT {type_courant = INT; printf("Type int\n");} ;
|
|
134
|
+Type : tINT {type_courant.base = INT; type_courant.pointeur_level = 0; printf("Type int\n");} ;
|
|
135
|
+Type : Type tMUL {type_courant.pointeur_level++; printf("Type int *\n");};
|
|
136
|
+//SuiteType : tMUL SuiteType {type_courant.pointeur_level++; printf(" * en plus\n");} ;
|
|
137
|
+//SuiteType : ;
|
141
|
138
|
|
142
|
|
-Decl : DeclType SuiteDecl FinDecl ;
|
143
|
|
-Decl : tCONST DeclType SuiteDeclConst FinDeclConst;
|
|
139
|
+Decl : Type SuiteDecl FinDecl ;
|
|
140
|
+Decl : tCONST Type SuiteDeclConst FinDeclConst;
|
144
|
141
|
|
145
|
142
|
SuiteDecl : tID {push($1, 0, type_courant); printf("Suite Decl\n");};
|
146
|
143
|
SuiteDecl : tID tEQ E {int addr = push($1,1, type_courant); add_operation(COP, addr,$3,0);};
|