diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/generator.c | 8 | ||||
-rw-r--r-- | src/tpc.y | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/src/generator.c b/src/generator.c index 3ecfe0d..dc85517 100644 --- a/src/generator.c +++ b/src/generator.c | |||
@@ -266,7 +266,7 @@ void gen_or(int left, int right, int idx) { | |||
266 | fprintf(output, "jmp .false%d\n", idx); | 266 | fprintf(output, "jmp .false%d\n", idx); |
267 | fprintf(output, ".true%d:\n", idx); | 267 | fprintf(output, ".true%d:\n", idx); |
268 | fprintf(output, "push 1\n"); | 268 | fprintf(output, "push 1\n"); |
269 | fprintf(output, ".false%d:", idx); | 269 | fprintf(output, ".false%d:\n", idx); |
270 | } | 270 | } |
271 | 271 | ||
272 | void gen_and(int left, int right, int idx) { | 272 | void gen_and(int left, int right, int idx) { |
@@ -284,7 +284,7 @@ void gen_and(int left, int right, int idx) { | |||
284 | fprintf(output, "jmp .true%d\n", idx); | 284 | fprintf(output, "jmp .true%d\n", idx); |
285 | fprintf(output, ".false%d:\n", idx); | 285 | fprintf(output, ".false%d:\n", idx); |
286 | fprintf(output, "push 0\n"); | 286 | fprintf(output, "push 0\n"); |
287 | fprintf(output, ".true%d:", idx); | 287 | fprintf(output, ".true%d:\n", idx); |
288 | } | 288 | } |
289 | 289 | ||
290 | void gen_eq(const char op[], int left, int right, int idx) { | 290 | void gen_eq(const char op[], int left, int right, int idx) { |
@@ -300,7 +300,7 @@ void gen_eq(const char op[], int left, int right, int idx) { | |||
300 | else | 300 | else |
301 | exit(1); // TODO: error on unexpected op | 301 | exit(1); // TODO: error on unexpected op |
302 | 302 | ||
303 | fprintf(output, "push 0\njmp .false%d\n.true%d:\npush 1\n.false%d:", idx, idx, | 303 | fprintf(output, "push 0\njmp .false%d\n.true%d:\npush 1\n.false%d:\n", idx, idx, |
304 | idx); | 304 | idx); |
305 | } | 305 | } |
306 | 306 | ||
@@ -321,7 +321,7 @@ void gen_order(const char op[], int left, int right, int idx) { | |||
321 | else | 321 | else |
322 | exit(1); // TODO: error on unexpected op | 322 | exit(1); // TODO: error on unexpected op |
323 | 323 | ||
324 | fprintf(output, "push 0\njmp .false%d\n.true%d:\npush 1\n.false%d:", idx, idx, | 324 | fprintf(output, "push 0\njmp .false%d\n.true%d:\npush 1\n.false%d:\n", idx, idx, |
325 | idx); | 325 | idx); |
326 | } | 326 | } |
327 | 327 | ||
@@ -126,7 +126,7 @@ Instr: | |||
126 | | PRINT '(' Exp ')' ';' { gen_print($<type>3);} | 126 | | PRINT '(' Exp ')' ';' { gen_print($<type>3);} |
127 | | IF '(' Exp IfHandling')' Instr { gen_if_label($<num>4); } | 127 | | IF '(' Exp IfHandling')' Instr { gen_if_label($<num>4); } |
128 | | IF '(' Exp IfHandling')' Instr ELSE IfEndHandling Instr IfElseEndHandling | 128 | | IF '(' Exp IfHandling')' Instr ELSE IfEndHandling Instr IfElseEndHandling |
129 | | WHILE '(' Exp ')' Instr | 129 | | WHILE {fprintf(output,".upwhile%d:\n",num_while);}'(' Exp {fprintf(output,"pop rax\ncmp rax,0\njz .downwhile%d\n",num_while);}')' Instr {fprintf(output,"jmp .upwhile%d\n.downwhile%d:\n",num_while,num_while);num_while++;} |
130 | | '{' SuiteInstr '}' | 130 | | '{' SuiteInstr '}' |
131 | ; | 131 | ; |
132 | IfHandling: { gen_if_start($<num>$ = num_if++); }; | 132 | IfHandling: { gen_if_start($<num>$ = num_if++); }; |