From 7ab0b07d8224280330320238c45889c460cd0bda Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Wed, 6 Jun 2018 02:14:35 +0200 Subject: Fix const + fix entier x,y,... --- res/nani.tpc | 1 - res/test_if.tpc | 14 ++++++++++++-- src/generator.c | 2 +- src/tpc.y | 9 +++++---- 4 files changed, 18 insertions(+), 8 deletions(-) delete mode 100644 res/nani.tpc 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 @@ -/*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 @@ /* Test file for simplified translator of a declaration of variables in C */ entier main(void) { - entier bool1,bool2; + entier bool1, bool2; bool1 = 0; bool2 = 0; if(bool1 == bool2){ - print(0); + if(bool1 != bool2){ + print('n'); + } + else{ + if(bool1 <= bool2){ + print('o'); + return 0; + } + print('n'); + } } + return 0; } 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) { case GLOBAL: if (is_read_only(ident, scope)) - fprintf(output, "push QWORD %s\n", ident); + fprintf(output, "push QWORD [%s]\n", ident); else fprintf(output, "push QWORD [globals + %d] ;%s\n", glo_get_addr(ident), 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; static int nb_param[255]; static int num_scope = -1; static char fname[64]; +static Type type; %} %union { @@ -75,15 +76,15 @@ NombreSigne: | ADDSUB NUM { $$ = $1 == '-' ? - $2 : $2; } ; DeclVars: - DeclVars TYPE Declarateurs ';' + DeclVars TYPE Declarateurs ';' {type = $2;} | ; Declarateurs: - Declarateurs ',' Declarateur -| Declarateur + Declarateurs ',' Declarateur +| Declarateur ; Declarateur: - IDENT { gen_declaration($1, $0, scope);} + IDENT { gen_declaration($1, type, scope);} | IDENT '[' NUM ']' { gen_tab_declaration($1, scope, $3);} ; DeclFoncts: -- cgit v1.2.3