|
@@ -10,7 +10,8 @@
|
10
|
10
|
%union {
|
11
|
11
|
int nombre;
|
12
|
12
|
struct symbole_t symbole;
|
13
|
|
- char id[30];
|
|
13
|
+ char id[30];
|
|
14
|
+ char str[300];
|
14
|
15
|
struct while_t my_while;
|
15
|
16
|
}
|
16
|
17
|
%{
|
|
@@ -45,7 +46,8 @@ int first_etoile = 1;
|
45
|
46
|
%token tMUL tDIV tADD tSUB tEQ
|
46
|
47
|
%token<nombre> tNB tNBEXP
|
47
|
48
|
%token<id> tID
|
48
|
|
-%token tPRINTF tGET tSTOP
|
|
49
|
+%token<str> tSTR
|
|
50
|
+%token tPRINT tGET tSTOP
|
49
|
51
|
%token<nombre> tIF tELSE
|
50
|
52
|
%token<my_while> tWHILE
|
51
|
53
|
%token tRETURN
|
|
@@ -116,10 +118,84 @@ Get : tGET tOBRACE tCBRACE {int addr = push("0_TEMPORARY", 0, integer);
|
116
|
118
|
};
|
117
|
119
|
|
118
|
120
|
// Print, une fonction particulière
|
119
|
|
-Print : tPRINTF tOBRACE E tCBRACE {add_operation(PRI,$3,0,0); // On ajoute l'instruction PRI
|
120
|
|
- pop(); // On supprime la variable temporaire
|
|
121
|
+Print : tPRINT tOBRACE E tCBRACE {add_operation(PRI,$3,0,0); // On ajoute l'instruction PRI
|
|
122
|
+ pop(); // On supprime la variable temporaire
|
121
|
123
|
};
|
122
|
124
|
|
|
125
|
+// Print, une fonction particulière
|
|
126
|
+Print : tPRINT tOBRACE tSTR tCBRACE {int i = 0;
|
|
127
|
+ int decalage = 0;
|
|
128
|
+ char previous = 'a';
|
|
129
|
+ while ($3[i] != '\0') {
|
|
130
|
+ if (previous == '\\' && $3[i] == 'n') {
|
|
131
|
+ $3[i - decalage - 1] = '\n';
|
|
132
|
+ previous = 'a';
|
|
133
|
+ decalage++;
|
|
134
|
+ } else {
|
|
135
|
+ $3[i-decalage] = $3[i];
|
|
136
|
+ previous = $3[i];
|
|
137
|
+ }
|
|
138
|
+ i++;
|
|
139
|
+ }
|
|
140
|
+ $3[i-decalage] = $3[i];
|
|
141
|
+ i=0;
|
|
142
|
+ int termine = $3[i+1] == '"';
|
|
143
|
+ int addr = push("0_TEMPORARY", 0, integer);
|
|
144
|
+ while (!termine) {
|
|
145
|
+ if ($3[i+1] != '"') {
|
|
146
|
+ add_operation(AFC, addr + i, $3[i+1], 0);
|
|
147
|
+ } else {
|
|
148
|
+ termine = 1;
|
|
149
|
+ }
|
|
150
|
+ i++;
|
|
151
|
+ if (!termine && $3[i+1] != '"') {
|
|
152
|
+ add_operation(AFC, addr + i, $3[i+1], 0);
|
|
153
|
+ } else {
|
|
154
|
+ termine = 1;
|
|
155
|
+ }
|
|
156
|
+ i++;
|
|
157
|
+ if (!termine && $3[i+1] != '"') {
|
|
158
|
+ add_operation(AFC, addr + i, $3[i+1], 0);
|
|
159
|
+ } else {
|
|
160
|
+ termine = 1;
|
|
161
|
+ }
|
|
162
|
+ i++;
|
|
163
|
+ if (!termine && $3[i+1] != '"') {
|
|
164
|
+ add_operation(AFC, addr + i, $3[i+1], 0);
|
|
165
|
+ } else {
|
|
166
|
+ termine = 1;
|
|
167
|
+ }
|
|
168
|
+
|
|
169
|
+ i = i - 3;
|
|
170
|
+ termine = 0;
|
|
171
|
+ if ($3[i+1] != '"') {
|
|
172
|
+ add_operation(PRIC, addr + i, 0, 0);
|
|
173
|
+ } else {
|
|
174
|
+ termine = 1;
|
|
175
|
+ }
|
|
176
|
+ i++;
|
|
177
|
+ if (!termine && $3[i+1] != '"') {
|
|
178
|
+ add_operation(PRIC, addr + i, 0, 0);
|
|
179
|
+ } else {
|
|
180
|
+ termine = 1;
|
|
181
|
+ }
|
|
182
|
+ i++;
|
|
183
|
+ if (!termine && $3[i+1] != '"') {
|
|
184
|
+ add_operation(PRIC, addr + i, 0, 0);
|
|
185
|
+ } else {
|
|
186
|
+ termine = 1;
|
|
187
|
+ }
|
|
188
|
+ i++;
|
|
189
|
+ if (!termine && $3[i+1] != '"') {
|
|
190
|
+ add_operation(PRIC, addr + i, 0, 0);
|
|
191
|
+ } else {
|
|
192
|
+ termine = 1;
|
|
193
|
+ }
|
|
194
|
+ i++;
|
|
195
|
+ }
|
|
196
|
+ pop(); // On supprime la variable temporaire
|
|
197
|
+ };
|
|
198
|
+
|
123
|
199
|
// Stop, une fonction particulière
|
124
|
200
|
Stop : tSTOP tOBRACE tNB tCBRACE {add_operation(STOP,$3,0,0); // On ajoute juste l'instruction stop
|
125
|
201
|
};
|