aboutsummaryrefslogtreecommitdiff
path: root/src/tpc.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/tpc.y')
-rw-r--r--src/tpc.y44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/tpc.y b/src/tpc.y
index a44a9aa..f1a51ff 100644
--- a/src/tpc.y
+++ b/src/tpc.y
@@ -5,6 +5,7 @@
5 */ 5 */
6 6
7#include <stdio.h> 7#include <stdio.h>
8#include "symboltable.h"
8 9
9extern int lineno; 10extern int lineno;
10int yylex(); 11int 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 ;
124F: 138F:
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 ;
133LValue: 147LValue:
134 IDENT 148 IDENT {lookup($<ident>1);}
135 | IDENT '[' Exp ']' 149 | IDENT '[' Exp ']' {lookup($<ident>1);}
136 ; 150 ;
137Arguments: 151Arguments:
138 ListExp 152 ListExp