aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam NAILI2018-06-06 03:06:34 +0200
committerAdam NAILI2018-06-06 03:06:34 +0200
commit38771494bada2b71a5e3a320938e6a259c1e208c (patch)
treec8c14d57d981a67802d75f966267e0fd64563605 /src
parent7ab0b07d8224280330320238c45889c460cd0bda (diff)
downloadtpc-compiler-38771494bada2b71a5e3a320938e6a259c1e208c.tar.gz
Fixing chain declarator and array conflict
Diffstat (limited to 'src')
-rw-r--r--src/tpc.y31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/tpc.y b/src/tpc.y
index 50bfa5d..59fa9d1 100644
--- a/src/tpc.y
+++ b/src/tpc.y
@@ -26,8 +26,9 @@ static int num_if = 0;
26static int num_while = 0; 26static int num_while = 0;
27static int nb_param[255]; 27static int nb_param[255];
28static int num_scope = -1; 28static int num_scope = -1;
29static int offset = 0;
30static int is_array = 0;
29static char fname[64]; 31static char fname[64];
30static 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;
78DeclVars: 79DeclVars:
79 DeclVars TYPE Declarateurs ';' {type = $<type>2;} 80 DeclVars TYPE Declarateurs ';'
80| 81|
81; 82;
82Declarateurs: 83Declarateurs:
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;
86Declarateur: 99Declarateur:
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;
90DeclFoncts: 103DeclFoncts:
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;
184LValue: 197LValue:
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;
188Arguments: 201Arguments:
189 ListExp 202 ListExp