aboutsummaryrefslogtreecommitdiff
path: root/src/tpc.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/tpc.y')
-rw-r--r--src/tpc.y27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/tpc.y b/src/tpc.y
index 2938094..293f28e 100644
--- a/src/tpc.y
+++ b/src/tpc.y
@@ -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;
90DeclFonct: 89DeclFonct:
91 EnTeteFonct { scope = LOCAL; } 90 EnTeteFonct { scope = LOCAL; }
92 Corps { scope = GLOBAL; } 91 Corps { gen_function_end_declaration(); scope = GLOBAL; }
93; 92;
94EnTeteFonct: 93EnTeteFonct:
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
99PrologueCont: {gen_prologue_continue(&bss_done);}; 98PrologueCont: {gen_prologue_continue(&bss_done);};
100 99
101Parametres: 100Parametres:
102 VOID 101 VOID {$$ = 0;}
103| ListTypVar 102| ListTypVar { $<num>$ = $<num>1;}
104; 103;
105ListTypVar: 104ListTypVar:
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;
109Corps: 108Corps:
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;
169LValue: 168LValue:
170 IDENT { gen_read($<ident>1, scope); } 169 IDENT { gen_read($<ident>1, scope); }
@@ -172,11 +171,11 @@ LValue:
172; 171;
173Arguments: 172Arguments:
174 ListExp 173 ListExp
175| 174| {$<num>$ = 0;}
176; 175;
177ListExp: 176ListExp:
178 ListExp ',' Exp 177 ListExp ',' Exp {$<num>$ = $<num>1 + 1;}
179| Exp 178| Exp {$<num>$ = 1;}
180; 179;
181%% 180%%
182 181