diff options
author | Adam NAILI | 2018-06-03 15:30:53 +0200 |
---|---|---|
committer | Adam NAILI | 2018-06-03 15:30:53 +0200 |
commit | b8f7e7b6843c2bff778ce3c74e355a03e7565499 (patch) | |
tree | 9a99518d868af17e5c82ee892f0fde65cf361da5 /src/tpc.y | |
parent | 628b18fb15ee3d6633c73d404f109d01f0a7ece2 (diff) | |
download | tpc-compiler-b8f7e7b6843c2bff778ce3c74e355a03e7565499.tar.gz |
Functions tables + void functions working (need to work on returns and parameters cause all functions are void here)
Diffstat (limited to 'src/tpc.y')
-rw-r--r-- | src/tpc.y | 27 |
1 files changed, 13 insertions, 14 deletions
@@ -5,9 +5,8 @@ | |||
5 | * | 5 | * |
6 | * TODO : | 6 | * TODO : |
7 | * ------ | 7 | * ------ |
8 | * - Gérer les globales avec .bss (Il faut donc décaler le début du programme après l'analyse des globales pour savoir combien de place réserver.) | ||
9 | * - Gestion des tableaux | 8 | * - Gestion des tableaux |
10 | * - Tableau des fonctions | 9 | * - Fonctions avec paramètres et retour de fonctions (void fonctions déjà fonctionnelles) |
11 | * | 10 | * |
12 | */ | 11 | */ |
13 | 12 | ||
@@ -44,7 +43,7 @@ static int num_if = 0; | |||
44 | %token OR AND CONST IF ELSE WHILE RETURN VOID PRINT READC READE | 43 | %token OR AND CONST IF ELSE WHILE RETURN VOID PRINT READC READE |
45 | %token <type> TYPE | 44 | %token <type> TYPE |
46 | 45 | ||
47 | %type <num> Exp EB TB FB M E T F | 46 | %type <num> Exp EB TB FB M E T F Parametres |
48 | %type <ident> LValue | 47 | %type <ident> LValue |
49 | 48 | ||
50 | %left ',' | 49 | %left ',' |
@@ -89,22 +88,22 @@ DeclFoncts: | |||
89 | ; | 88 | ; |
90 | DeclFonct: | 89 | DeclFonct: |
91 | EnTeteFonct { scope = LOCAL; } | 90 | EnTeteFonct { scope = LOCAL; } |
92 | Corps { scope = GLOBAL; } | 91 | Corps { gen_function_end_declaration(); scope = GLOBAL; } |
93 | ; | 92 | ; |
94 | EnTeteFonct: | 93 | EnTeteFonct: |
95 | TYPE IDENT PrologueCont '(' Parametres ')' | 94 | TYPE IDENT PrologueCont '(' Parametres ')' {gen_function_declaration($<ident>2, $<type>1, $5);} |
96 | | VOID IDENT PrologueCont '(' Parametres ')' | 95 | | VOID IDENT PrologueCont '(' Parametres ')' {gen_function_declaration($<ident>2, 2, $5);} |
97 | ; | 96 | ; |
98 | 97 | ||
99 | PrologueCont: {gen_prologue_continue(&bss_done);}; | 98 | PrologueCont: {gen_prologue_continue(&bss_done);}; |
100 | 99 | ||
101 | Parametres: | 100 | Parametres: |
102 | VOID | 101 | VOID {$$ = 0;} |
103 | | ListTypVar | 102 | | ListTypVar { $<num>$ = $<num>1;} |
104 | ; | 103 | ; |
105 | ListTypVar: | 104 | ListTypVar: |
106 | ListTypVar ',' TYPE IDENT { gen_declaration($<ident>4, $<type>3, scope); } | 105 | ListTypVar ',' TYPE IDENT { gen_declaration($<ident>4, $<type>3, scope); $<num>$ = $<num>1+1; } |
107 | | TYPE IDENT { gen_declaration($<ident>2, $<type>1, scope); } | 106 | | TYPE IDENT { gen_declaration($<ident>2, $<type>1, scope); $<num>$ = 1; } |
108 | ; | 107 | ; |
109 | Corps: | 108 | Corps: |
110 | '{' DeclConsts DeclVars SuiteInstr '}' | 109 | '{' DeclConsts DeclVars SuiteInstr '}' |
@@ -164,7 +163,7 @@ F: | |||
164 | | LValue { $$ = gen_value($<ident>1, scope); } | 163 | | LValue { $$ = gen_value($<ident>1, scope); } |
165 | | NUM { $$ = gen_num($1, scope); } | 164 | | NUM { $$ = gen_num($1, scope); } |
166 | | CARACTERE { $$ = gen_char($1, scope); } | 165 | | CARACTERE { $$ = gen_char($1, scope); } |
167 | | IDENT '(' Arguments ')' { $$ = INT; } // tableau d'entiers uniquement | 166 | | IDENT '(' Arguments ')' { $$ = gen_function_call($<ident>1,$<num>3);} |
168 | ; | 167 | ; |
169 | LValue: | 168 | LValue: |
170 | IDENT { gen_read($<ident>1, scope); } | 169 | IDENT { gen_read($<ident>1, scope); } |
@@ -172,11 +171,11 @@ LValue: | |||
172 | ; | 171 | ; |
173 | Arguments: | 172 | Arguments: |
174 | ListExp | 173 | ListExp |
175 | | | 174 | | {$<num>$ = 0;} |
176 | ; | 175 | ; |
177 | ListExp: | 176 | ListExp: |
178 | ListExp ',' Exp | 177 | ListExp ',' Exp {$<num>$ = $<num>1 + 1;} |
179 | | Exp | 178 | | Exp {$<num>$ = 1;} |
180 | ; | 179 | ; |
181 | %% | 180 | %% |
182 | 181 | ||