diff options
author | Adam NAILI | 2018-06-06 02:14:35 +0200 |
---|---|---|
committer | Adam NAILI | 2018-06-06 02:14:35 +0200 |
commit | 7ab0b07d8224280330320238c45889c460cd0bda (patch) | |
tree | 93695a064ffdfabe1d113d5f5ebb77addbb775b2 | |
parent | d9f0d3f59f39f7787b0aa41a8e2e82244bad9d37 (diff) | |
download | tpc-compiler-7ab0b07d8224280330320238c45889c460cd0bda.tar.gz |
Fix const + fix entier x,y,...
-rw-r--r-- | res/nani.tpc | 1 | ||||
-rw-r--r-- | res/test_if.tpc | 14 | ||||
-rw-r--r-- | src/generator.c | 2 | ||||
-rw-r--r-- | src/tpc.y | 9 |
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 | ||
5 | entier main(void) { | 5 | entier 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); |
@@ -27,6 +27,7 @@ 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 char fname[64]; | 29 | static char fname[64]; |
30 | static 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 | ; |
77 | DeclVars: | 78 | DeclVars: |
78 | DeclVars TYPE Declarateurs ';' | 79 | DeclVars TYPE Declarateurs ';' {type = $<type>2;} |
79 | | | 80 | | |
80 | ; | 81 | ; |
81 | Declarateurs: | 82 | Declarateurs: |
82 | Declarateurs ',' Declarateur | 83 | Declarateurs ',' Declarateur |
83 | | Declarateur | 84 | | Declarateur |
84 | ; | 85 | ; |
85 | Declarateur: | 86 | Declarateur: |
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 | ; |
89 | DeclFoncts: | 90 | DeclFoncts: |