diff options
Diffstat (limited to 'src/tpc.y')
-rw-r--r-- | src/tpc.y | 40 |
1 files changed, 17 insertions, 23 deletions
@@ -3,21 +3,16 @@ | |||
3 | * UPEM / Compilation / Projet | 3 | * UPEM / Compilation / Projet |
4 | * Pacien TRAN-GIRARD, Adam NAILI | 4 | * Pacien TRAN-GIRARD, Adam NAILI |
5 | * | 5 | * |
6 | * | 6 | * TODO : |
7 | * | ||
8 | * | ||
9 | * | ||
10 | * | ||
11 | * TODO : | ||
12 | * ------ | 7 | * ------ |
13 | * - Gérer les globales avec .bss (Il faut donc décaler le début du programme après l'analyse des globales pour savoir combien de place réserver.) | 8 | * - Gérer les globales avec .bss (Il faut donc décaler le début du programme après l'analyse des globales pour savoir combien de place réserver.) |
14 | * - Gestion des tableaux | 9 | * - Gestion des tableaux |
15 | * - Tableau des fonctions | 10 | * - Tableau des fonctions |
16 | * | 11 | * |
17 | */ | 12 | */ |
18 | 13 | ||
19 | #include <stdio.h> | 14 | #include <stdio.h> |
20 | #include "symboltable.h" | 15 | #include "symbol_table.h" |
21 | 16 | ||
22 | extern int lineno; | 17 | extern int lineno; |
23 | int yylex(); | 18 | int yylex(); |
@@ -30,13 +25,13 @@ static int num_if = 0; | |||
30 | %} | 25 | %} |
31 | 26 | ||
32 | %union { | 27 | %union { |
33 | char caractere; | 28 | char caractere; |
34 | int num; | 29 | int num; |
35 | char ident[64]; | 30 | char ident[64]; |
36 | int type; | 31 | int type; |
37 | char comp[3]; | 32 | char comp[3]; |
38 | char addsub; | 33 | char addsub; |
39 | char divstar; | 34 | char divstar; |
40 | } | 35 | } |
41 | %token <caractere> CARACTERE | 36 | %token <caractere> CARACTERE |
42 | %token <num> NUM | 37 | %token <num> NUM |
@@ -47,7 +42,7 @@ static int num_if = 0; | |||
47 | %token OR AND CONST IF ELSE WHILE RETURN VOID PRINT READC READE | 42 | %token OR AND CONST IF ELSE WHILE RETURN VOID PRINT READC READE |
48 | %token <type> TYPE | 43 | %token <type> TYPE |
49 | 44 | ||
50 | %type <num> Exp EB TB FB M E T F | 45 | %type <num> Exp EB TB FB M E T F |
51 | %type <ident> LValue | 46 | %type <ident> LValue |
52 | 47 | ||
53 | %left ',' | 48 | %left ',' |
@@ -66,17 +61,17 @@ Prog:{printf("extern printf\n"); | |||
66 | printf("mov rsi, rax\n"); | 61 | printf("mov rsi, rax\n"); |
67 | printf("mov rdi, format_int\n"); | 62 | printf("mov rdi, format_int\n"); |
68 | printf("mov rax, 0\n"); | 63 | printf("mov rax, 0\n"); |
69 | printf("call printf WRT ..plt\n"); | 64 | printf("call printf WRT ..plt\n"); |
70 | printf("pop rsi\n"); | 65 | printf("pop rsi\n"); |
71 | printf("pop rbp\n"); | 66 | printf("pop rbp\n"); |
72 | printf("ret\n"); | 67 | printf("ret\n"); |
73 | printf("\n_start:\n"); | 68 | printf("\n_start:\n"); |
74 | printf("push rbp\nmov rbp, rsp\n\n"); | 69 | printf("push rbp\nmov rbp, rsp\n\n"); |
75 | } | 70 | } |
76 | DeclConsts DeclVars DeclFoncts | 71 | DeclConsts DeclVars DeclFoncts |
77 | { | 72 | { |
78 | printf("mov rax,60 \n"); | 73 | printf("mov rax,60 \n"); |
79 | printf("mov rdi,0 \n"); | 74 | printf("mov rdi,0 \n"); |
80 | printf("syscall \n"); | 75 | printf("syscall \n"); |
81 | printf(";global table\n"); | 76 | printf(";global table\n"); |
82 | glo_display_table(); | 77 | glo_display_table(); |
@@ -278,8 +273,8 @@ F: | |||
278 | else{ | 273 | else{ |
279 | printf(";-F\npop rdx\nxor rax,rax\nsub rax,rdx\npush rax\n"); | 274 | printf(";-F\npop rdx\nxor rax,rax\nsub rax,rdx\npush rax\n"); |
280 | } | 275 | } |
281 | } | 276 | } |
282 | | '!' F {$$ = $2;printf(";!F\npop rax\nxor rax,1\npush rax\n");} | 277 | | '!' F {$$ = $2;printf(";!F\npop rax\nxor rax,1\npush rax\n");} |
283 | | '(' Exp ')' {$$ = $2;} | 278 | | '(' Exp ')' {$$ = $2;} |
284 | | LValue { | 279 | | LValue { |
285 | if(status == GLOBAL) { | 280 | if(status == GLOBAL) { |
@@ -330,4 +325,3 @@ void yyerror(char *msg){ | |||
330 | int main(int argc, char **argv) { | 325 | int main(int argc, char **argv) { |
331 | return yyparse(); | 326 | return yyparse(); |
332 | } | 327 | } |
333 | |||