diff options
Diffstat (limited to 'src/tpc.y')
-rw-r--r-- | src/tpc.y | 44 |
1 files changed, 29 insertions, 15 deletions
@@ -5,6 +5,7 @@ | |||
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | #include "symboltable.h" | ||
8 | 9 | ||
9 | extern int lineno; | 10 | extern int lineno; |
10 | int yylex(); | 11 | int yylex(); |
@@ -12,12 +13,25 @@ void yyerror(char *); | |||
12 | 13 | ||
13 | %} | 14 | %} |
14 | 15 | ||
15 | %token CARACTERE NUM IDENT | 16 | %union { |
16 | %token ADDSUB DIVSTAR | 17 | char caractere; |
17 | %token ORDER EQ OR AND | 18 | int num; |
18 | %token IF WHILE RETURN | 19 | char ident[64]; |
19 | %token CONST VOID TYPE | 20 | char type[32]; |
20 | %token PRINT READC READE | 21 | char comp[3]; |
22 | char addsub; | ||
23 | char divstar; | ||
24 | } | ||
25 | %token <caractere> CARACTERE | ||
26 | %token <num> NUM | ||
27 | %token <ident> IDENT | ||
28 | %token <comp> ORDER EQ | ||
29 | %token <addsub> ADDSUB | ||
30 | %token <divstar> DIVSTAR | ||
31 | %token OR AND CONST IF ELSE WHILE RETURN VOID PRINT READC READE | ||
32 | %token <type> TYPE | ||
33 | |||
34 | %type <num> Exp EB TB FB M E T F LValue | ||
21 | 35 | ||
22 | %left ',' | 36 | %left ',' |
23 | %precedence ')' | 37 | %precedence ')' |
@@ -122,17 +136,17 @@ T: | |||
122 | | F | 136 | | F |
123 | ; | 137 | ; |
124 | F: | 138 | F: |
125 | ADDSUB F | 139 | ADDSUB F {$$ = $2;} //on fait remonter le type |
126 | | '!' F | 140 | | '!' F {$$ = $2;} |
127 | | '(' Exp ')' | 141 | | '(' Exp ')' {$$ = $2;} |
128 | | LValue | 142 | | LValue //Il faut trouver le type de LValue |
129 | | NUM | 143 | | NUM {$$ = INT;} // on stocke les types pour l'analyse sémantique |
130 | | CARACTERE | 144 | | CARACTERE {$$ = CHAR;} |
131 | | IDENT '(' Arguments ')' | 145 | | IDENT '(' Arguments ')' {$$ = INT;} //tableau d'entiers uniquement |
132 | ; | 146 | ; |
133 | LValue: | 147 | LValue: |
134 | IDENT | 148 | IDENT {lookup($<ident>1);} |
135 | | IDENT '[' Exp ']' | 149 | | IDENT '[' Exp ']' {lookup($<ident>1);} |
136 | ; | 150 | ; |
137 | Arguments: | 151 | Arguments: |
138 | ListExp | 152 | ListExp |