|
@@ -16,7 +16,9 @@ InstructionTable instruction_table;
|
16
|
16
|
char* symbol_name;
|
17
|
17
|
SymbolItem* symbol;
|
18
|
18
|
int nombre;
|
|
19
|
+ int address;
|
19
|
20
|
Instruction instruction;
|
|
21
|
+ struct Condition* condition;
|
20
|
22
|
}
|
21
|
23
|
|
22
|
24
|
%token<nombre> tNB
|
|
@@ -31,13 +33,13 @@ InstructionTable instruction_table;
|
31
|
33
|
%token tAO
|
32
|
34
|
%token tAF
|
33
|
35
|
%token tEQ
|
34
|
|
-%token tEQ2
|
35
|
|
-%token tNOTEQ
|
|
36
|
+%token<condition> tEQ2
|
|
37
|
+%token<condition> tNOTEQ
|
|
38
|
+%token<condition> tINF
|
|
39
|
+%token<condition> tINFEQ
|
|
40
|
+%token<condition> tSUP
|
|
41
|
+%token<condition> tSUPEQ
|
36
|
42
|
%token tNOT
|
37
|
|
-%token tINF
|
38
|
|
-%token tINFEQ
|
39
|
|
-%token tSUP
|
40
|
|
-%token tSUPEQ
|
41
|
43
|
%token tAND
|
42
|
44
|
%token tOR
|
43
|
45
|
|
|
@@ -56,6 +58,8 @@ InstructionTable instruction_table;
|
56
|
58
|
%left tMUL
|
57
|
59
|
%left tDIV
|
58
|
60
|
%type<symbol> E
|
|
61
|
+%type<symbol> Cond
|
|
62
|
+%type<address> IfSimple
|
59
|
63
|
|
60
|
64
|
%%
|
61
|
65
|
|
|
@@ -74,7 +78,7 @@ Body : tAO Instructions tAF { printf("Body\n"); } ;
|
74
|
78
|
|
75
|
79
|
Instructions : Instruction Instructions | { printf("Instructions\n"); } ;
|
76
|
80
|
|
77
|
|
-Instruction : Aff | Printf { printf("Instruction\n"); } ;
|
|
81
|
+Instruction : Aff | Printf | If { printf("Instruction\n"); } ;
|
78
|
82
|
|
79
|
83
|
Aff : tID tEQ E tPV { write_affectation(&symbol_table, &instruction_table, $1, $3); } ;
|
80
|
84
|
|
|
@@ -97,29 +101,28 @@ DeclarationConst : tCONST { current_type = TYPE_CONST; } DeclarationBody tPV ;
|
97
|
101
|
|
98
|
102
|
DeclarationBody : VariableIdentifier tVIRG DeclarationBody | VariableIdentifier ;
|
99
|
103
|
|
100
|
|
-VariableIdentifier: tID { add_symbol(&symbol_table, current_type, $1); }
|
|
104
|
+VariableIdentifier: tID { add_symbol(&symbol_table, current_type, $1); } ;
|
101
|
105
|
|
102
|
106
|
// While : tWHILE tPO Cond tPF Body { printf("While\n"); } ;
|
103
|
|
-//
|
104
|
|
-// If : IfSimple | IfElse { printf("If\n"); } ;
|
105
|
|
-//
|
106
|
|
-// IfSimple : tIF tPO Cond tPF Body { printf("IfSimple\n"); } ;
|
107
|
|
-//
|
108
|
|
-// IfElse : IfSimple tELSE Body { printf("IfElse\n"); } ;
|
109
|
|
-//
|
110
|
|
-// Cond : tNOT Cond | Cond tAND Cond | Cond tOR Cond | E tEQ2 E | E tINF E | E tINFEQ E | E tSUP E | E tSUPEQ E | E tNOTEQ E | tNOT tPO Cond tPF { printf("Cond\n"); } ;
|
111
|
107
|
|
112
|
|
-Printf : tPRINTF tPO E tPF tPV { write_print(&instruction_table, $3); } ;
|
|
108
|
+If : IfSimple { update_jmf(&instruction_table, $1); } ;
|
113
|
109
|
|
114
|
|
-// If : tIF tPO Cond tPF Body ;
|
115
|
|
-//
|
116
|
|
-// Cond : Cond tAND Cond | Cond tOR Cond | E tEQ2 E | E tINF E | tNOT Cond ;
|
|
110
|
+IfSimple : tIF tPO Cond tPF { $<address>$ = write_jmf(&instruction_table, $3); } Body { $$ = $<address>5; };
|
117
|
111
|
|
118
|
|
-// Invocation : tID tPO Args tPF ;
|
|
112
|
+// IfElse : IfSimple tELSE Body { printf("IfElse\n"); } ;
|
119
|
113
|
|
120
|
|
-// Args : .... cf params
|
|
114
|
+Cond : tNOT Cond { $$ = write_not_condition(&symbol_table, &instruction_table, $2); }
|
|
115
|
+| Cond tAND Cond { $$ = write_op(&symbol_table, &instruction_table, MUL, $1, $3); }
|
|
116
|
+| Cond tOR Cond { $$ = write_op(&symbol_table, &instruction_table, ADD, $1, $3); }
|
|
117
|
+| E tEQ2 E { $$ = write_condition(&symbol_table, &instruction_table, $2, $1, $3); }
|
|
118
|
+| E tINF E { $$ = write_condition(&symbol_table, &instruction_table, $2, $1, $3); }
|
|
119
|
+| E tINFEQ E { $$ = write_condition(&symbol_table, &instruction_table, $2, $1, $3); }
|
|
120
|
+| E tSUP E { $$ = write_condition(&symbol_table, &instruction_table, $2, $1, $3); }
|
|
121
|
+| E tSUPEQ E { $$ = write_condition(&symbol_table, &instruction_table, $2, $1, $3); }
|
|
122
|
+| E tNOTEQ E { $$ = write_condition(&symbol_table, &instruction_table, $2, $1, $3); }
|
|
123
|
+| tNOT tPO Cond tPF { $$ = write_not_condition(&symbol_table, &instruction_table, $3); } ;
|
121
|
124
|
|
122
|
|
-// Return : tRET E tPV ;
|
|
125
|
+Printf : tPRINTF tPO E tPF tPV { write_print(&instruction_table, $3); } ;
|
123
|
126
|
|
124
|
127
|
%%
|
125
|
128
|
|