diff options
author | pacien | 2018-06-05 13:41:13 +0200 |
---|---|---|
committer | pacien | 2018-06-05 13:41:13 +0200 |
commit | 8f6dd273479bdc7789d40a235b0afb6598fd0435 (patch) | |
tree | 3f30d4b2869e3460a587ab9e7708afe4a8cacca7 /src/tpc.y | |
parent | 7a966d25b34f4bd37f32a18f7e8a62b6f97186e6 (diff) | |
download | tpc-compiler-8f6dd273479bdc7789d40a235b0afb6598fd0435.tar.gz |
Handle func return
Diffstat (limited to 'src/tpc.y')
-rw-r--r-- | src/tpc.y | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -20,6 +20,7 @@ extern int lineno; | |||
20 | int yylex(); | 20 | int yylex(); |
21 | void yyerror(char *); | 21 | void yyerror(char *); |
22 | static Scope scope = GLOBAL; | 22 | static Scope scope = GLOBAL; |
23 | static Type return_type = VOID; | ||
23 | static int bss_done = 0; | 24 | static int bss_done = 0; |
24 | static int num_label = 0; | 25 | static int num_label = 0; |
25 | static int num_if = 0; | 26 | static int num_if = 0; |
@@ -88,11 +89,11 @@ DeclFoncts: | |||
88 | ; | 89 | ; |
89 | DeclFonct: | 90 | DeclFonct: |
90 | EnTeteFonct { scope = LOCAL; } | 91 | EnTeteFonct { scope = LOCAL; } |
91 | Corps { gen_function_end_declaration(); scope = GLOBAL; } | 92 | Corps { gen_function_end_declaration(); scope = GLOBAL; return_type = VOID; } |
92 | ; | 93 | ; |
93 | EnTeteFonct: | 94 | EnTeteFonct: |
94 | TYPE IDENT PrologueCont '(' Parametres ')' {gen_function_declaration($<ident>2, $<type>1, $5);} | 95 | TYPE IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($<ident>2, $<type>1, $5); } |
95 | | VOID IDENT PrologueCont '(' Parametres ')' {gen_function_declaration($<ident>2, 2, $5);} | 96 | | VOID IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($<ident>2, VOID, $5); } |
96 | ; | 97 | ; |
97 | 98 | ||
98 | PrologueCont: {gen_prologue_continue(&bss_done);}; | 99 | PrologueCont: {gen_prologue_continue(&bss_done);}; |
@@ -115,8 +116,8 @@ SuiteInstr: | |||
115 | Instr: | 116 | Instr: |
116 | Exp ';' | 117 | Exp ';' |
117 | | ';' | 118 | | ';' |
118 | | RETURN Exp ';' | 119 | | RETURN Exp ';' { gen_function_return(return_type, $<type>2); scope = GLOBAL; return_type = VOID; } |
119 | | RETURN ';' | 120 | | RETURN ';' { gen_function_return(return_type, VOID); scope = GLOBAL; return_type = VOID; } |
120 | | READE '(' IDENT ')' ';' { gen_reade($<ident>3); } | 121 | | READE '(' IDENT ')' ';' { gen_reade($<ident>3); } |
121 | | READC '(' IDENT ')' ';' { gen_readc($<ident>3); } | 122 | | READC '(' IDENT ')' ';' { gen_readc($<ident>3); } |
122 | | PRINT '(' Exp ')' ';' { gen_print($<type>3);} | 123 | | PRINT '(' Exp ')' ';' { gen_print($<type>3);} |