diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tpc.y | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -26,8 +26,9 @@ static int num_if = 0; | |||
26 | static int num_while = 0; | 26 | static int num_while = 0; |
27 | static int nb_param[255]; | 27 | static int nb_param[255]; |
28 | static int num_scope = -1; | 28 | static int num_scope = -1; |
29 | static int offset = 0; | ||
30 | static int is_array = 0; | ||
29 | static char fname[64]; | 31 | static char fname[64]; |
30 | static Type type; | ||
31 | %} | 32 | %} |
32 | 33 | ||
33 | %union { | 34 | %union { |
@@ -49,7 +50,7 @@ static Type type; | |||
49 | %token <type> TYPE | 50 | %token <type> TYPE |
50 | 51 | ||
51 | %type <num> Exp EB TB FB M E T F Parametres | 52 | %type <num> Exp EB TB FB M E T F Parametres |
52 | %type <ident> LValue | 53 | %type <ident> LValue Declarateur |
53 | 54 | ||
54 | %left ',' | 55 | %left ',' |
55 | %precedence ')' | 56 | %precedence ')' |
@@ -76,16 +77,28 @@ NombreSigne: | |||
76 | | ADDSUB NUM { $<num>$ = $<addsub>1 == '-' ? - $<num>2 : $<num>2; } | 77 | | ADDSUB NUM { $<num>$ = $<addsub>1 == '-' ? - $<num>2 : $<num>2; } |
77 | ; | 78 | ; |
78 | DeclVars: | 79 | DeclVars: |
79 | DeclVars TYPE Declarateurs ';' {type = $<type>2;} | 80 | DeclVars TYPE Declarateurs ';' |
80 | | | 81 | | |
81 | ; | 82 | ; |
82 | Declarateurs: | 83 | Declarateurs: |
83 | Declarateurs ',' Declarateur | 84 | Declarateurs ',' Declarateur { |
84 | | Declarateur | 85 | if(!is_array){ |
86 | gen_declaration($<ident>3, $<type>0, scope); | ||
87 | }else{ | ||
88 | gen_tab_declaration($<ident>3, scope, offset); | ||
89 | } | ||
90 | } | ||
91 | | Declarateur { | ||
92 | if(!is_array){ | ||
93 | gen_declaration($<ident>1, $<type>0, scope); | ||
94 | }else{ | ||
95 | gen_tab_declaration($<ident>1, scope, offset); | ||
96 | } | ||
97 | } | ||
85 | ; | 98 | ; |
86 | Declarateur: | 99 | Declarateur: |
87 | IDENT { gen_declaration($<ident>1, type, scope);} | 100 | IDENT {strcpy($$,$1);is_array = 0;} |
88 | | IDENT '[' NUM ']' { gen_tab_declaration($<ident>1, scope, $<num>3);} | 101 | | IDENT '[' NUM ']' {offset = $<num>3;strcpy($$,$1);is_array=1;} |
89 | ; | 102 | ; |
90 | DeclFoncts: | 103 | DeclFoncts: |
91 | DeclFoncts DeclFonct | 104 | DeclFoncts DeclFonct |
@@ -182,8 +195,8 @@ F: | |||
182 | | IDENT '(' Arguments ')' { $$ = gen_function_call($<ident>1,$<num>3); } | 195 | | IDENT '(' Arguments ')' { $$ = gen_function_call($<ident>1,$<num>3); } |
183 | ; | 196 | ; |
184 | LValue: | 197 | LValue: |
185 | IDENT { gen_check($<ident>1, scope); } | 198 | IDENT { gen_check($<ident>1, scope); strcpy($$, $1);} |
186 | | IDENT '[' Exp ']' { gen_check($<ident>1, scope); } | 199 | | IDENT '[' Exp ']' { gen_check($<ident>1, scope); strcpy($$, $1);} |
187 | ; | 200 | ; |
188 | Arguments: | 201 | Arguments: |
189 | ListExp | 202 | ListExp |