aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam NAILI2018-06-06 02:14:35 +0200
committerAdam NAILI2018-06-06 02:14:35 +0200
commit7ab0b07d8224280330320238c45889c460cd0bda (patch)
tree93695a064ffdfabe1d113d5f5ebb77addbb775b2
parentd9f0d3f59f39f7787b0aa41a8e2e82244bad9d37 (diff)
downloadtpc-compiler-7ab0b07d8224280330320238c45889c460cd0bda.tar.gz
Fix const + fix entier x,y,...
-rw-r--r--res/nani.tpc1
-rw-r--r--res/test_if.tpc14
-rw-r--r--src/generator.c2
-rw-r--r--src/tpc.y9
4 files changed, 18 insertions, 8 deletions
diff --git a/res/nani.tpc b/res/nani.tpc
deleted file mode 100644
index dbb3731..0000000
--- a/res/nani.tpc
+++ /dev/null
@@ -1 +0,0 @@
1/*Programme correct avec le compilateur mais qui ne devrait pas*/
diff --git a/res/test_if.tpc b/res/test_if.tpc
index adb097a..054811b 100644
--- a/res/test_if.tpc
+++ b/res/test_if.tpc
@@ -3,10 +3,20 @@
3/* Test file for simplified translator of a declaration of variables in C */ 3/* Test file for simplified translator of a declaration of variables in C */
4 4
5entier main(void) { 5entier main(void) {
6 entier bool1,bool2; 6 entier bool1, bool2;
7 bool1 = 0; 7 bool1 = 0;
8 bool2 = 0; 8 bool2 = 0;
9 if(bool1 == bool2){ 9 if(bool1 == bool2){
10 print(0); 10 if(bool1 != bool2){
11 print('n');
12 }
13 else{
14 if(bool1 <= bool2){
15 print('o');
16 return 0;
17 }
18 print('n');
19 }
11 } 20 }
21 return 0;
12} 22}
diff --git a/src/generator.c b/src/generator.c
index 1dfe8f3..bb95e08 100644
--- a/src/generator.c
+++ b/src/generator.c
@@ -456,7 +456,7 @@ int gen_value(const char ident[], Scope scope) {
456 456
457 case GLOBAL: 457 case GLOBAL:
458 if (is_read_only(ident, scope)) 458 if (is_read_only(ident, scope))
459 fprintf(output, "push QWORD %s\n", ident); 459 fprintf(output, "push QWORD [%s]\n", ident);
460 else 460 else
461 fprintf(output, "push QWORD [globals + %d] ;%s\n", glo_get_addr(ident), 461 fprintf(output, "push QWORD [globals + %d] ;%s\n", glo_get_addr(ident),
462 ident); 462 ident);
diff --git a/src/tpc.y b/src/tpc.y
index ff95f64..50bfa5d 100644
--- a/src/tpc.y
+++ b/src/tpc.y
@@ -27,6 +27,7 @@ static 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 char fname[64]; 29static char fname[64];
30static Type type;
30%} 31%}
31 32
32%union { 33%union {
@@ -75,15 +76,15 @@ NombreSigne:
75| ADDSUB NUM { $<num>$ = $<addsub>1 == '-' ? - $<num>2 : $<num>2; } 76| ADDSUB NUM { $<num>$ = $<addsub>1 == '-' ? - $<num>2 : $<num>2; }
76; 77;
77DeclVars: 78DeclVars:
78 DeclVars TYPE Declarateurs ';' 79 DeclVars TYPE Declarateurs ';' {type = $<type>2;}
79| 80|
80; 81;
81Declarateurs: 82Declarateurs:
82 Declarateurs ',' Declarateur 83 Declarateurs ',' Declarateur
83| Declarateur 84| Declarateur
84; 85;
85Declarateur: 86Declarateur:
86 IDENT { gen_declaration($<ident>1, $<type>0, scope);} 87 IDENT { gen_declaration($<ident>1, type, scope);}
87| IDENT '[' NUM ']' { gen_tab_declaration($<ident>1, scope, $<num>3);} 88| IDENT '[' NUM ']' { gen_tab_declaration($<ident>1, scope, $<num>3);}
88; 89;
89DeclFoncts: 90DeclFoncts: