diff options
author | Adam NAILI | 2018-04-22 15:32:40 +0200 |
---|---|---|
committer | Adam NAILI | 2018-04-22 15:32:40 +0200 |
commit | a431f189d33af68ea179e464c889761e65ed1f08 (patch) | |
tree | 2da926fa6eccd0d2b9459be841fd0168d474e607 /src/tpc.y | |
parent | 5d83670f6b0b142bcda19270d3c9b50f9370bee8 (diff) | |
download | tpc-compiler-a431f189d33af68ea179e464c889761e65ed1f08.tar.gz |
Basic implementation of the symbol table
Diffstat (limited to 'src/tpc.y')
-rw-r--r-- | src/tpc.y | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -17,7 +17,7 @@ void yyerror(char *); | |||
17 | char caractere; | 17 | char caractere; |
18 | int num; | 18 | int num; |
19 | char ident[64]; | 19 | char ident[64]; |
20 | char type[32]; | 20 | int type; |
21 | char comp[3]; | 21 | char comp[3]; |
22 | char addsub; | 22 | char addsub; |
23 | char divstar; | 23 | char divstar; |
@@ -39,7 +39,7 @@ void yyerror(char *); | |||
39 | 39 | ||
40 | %% | 40 | %% |
41 | Prog: | 41 | Prog: |
42 | DeclConsts DeclVars DeclFoncts | 42 | DeclConsts DeclVars DeclFoncts {display_table();} |
43 | ; | 43 | ; |
44 | DeclConsts: | 44 | DeclConsts: |
45 | DeclConsts CONST ListConst ';' | 45 | DeclConsts CONST ListConst ';' |
@@ -62,8 +62,8 @@ DeclVars: | |||
62 | | | 62 | | |
63 | ; | 63 | ; |
64 | Declarateurs: | 64 | Declarateurs: |
65 | Declarateurs ',' Declarateur | 65 | Declarateurs ',' Declarateur {addVar($<ident>3, $<type>0);} |
66 | | Declarateur | 66 | | Declarateur {addVar($<ident>1, $<type>0);} |
67 | ; | 67 | ; |
68 | Declarateur: | 68 | Declarateur: |
69 | IDENT | 69 | IDENT |
@@ -85,8 +85,8 @@ Parametres: | |||
85 | | ListTypVar | 85 | | ListTypVar |
86 | ; | 86 | ; |
87 | ListTypVar: | 87 | ListTypVar: |
88 | ListTypVar ',' TYPE IDENT | 88 | ListTypVar ',' TYPE IDENT {addVar($<ident>4, $<type>3);} |
89 | | TYPE IDENT | 89 | | TYPE IDENT {addVar($<ident>2, $<type>1);} |
90 | ; | 90 | ; |
91 | Corps: | 91 | Corps: |
92 | '{' DeclConsts DeclVars SuiteInstr '}' | 92 | '{' DeclConsts DeclVars SuiteInstr '}' |
@@ -99,8 +99,8 @@ Instr: | |||
99 | | ';' | 99 | | ';' |
100 | | RETURN Exp ';' | 100 | | RETURN Exp ';' |
101 | | RETURN ';' | 101 | | RETURN ';' |
102 | | READE '(' IDENT ')' ';' | 102 | | READE '(' IDENT ')' ';' {lookup($<ident>3);} |
103 | | READC '(' IDENT ')' ';' | 103 | | READC '(' IDENT ')' ';' {lookup($<ident>3);} |
104 | | PRINT '(' Exp ')' ';' | 104 | | PRINT '(' Exp ')' ';' |
105 | | IF '(' Exp ')' Instr | 105 | | IF '(' Exp ')' Instr |
106 | | IF '(' Exp ')' Instr ELSE Instr | 106 | | IF '(' Exp ')' Instr ELSE Instr |
@@ -139,14 +139,14 @@ F: | |||
139 | ADDSUB F {$$ = $2;} //on fait remonter le type | 139 | ADDSUB F {$$ = $2;} //on fait remonter le type |
140 | | '!' F {$$ = $2;} | 140 | | '!' F {$$ = $2;} |
141 | | '(' Exp ')' {$$ = $2;} | 141 | | '(' Exp ')' {$$ = $2;} |
142 | | LValue //Il faut trouver le type de LValue | 142 | | LValue {$$ = $1;} |
143 | | NUM {$$ = INT;} // on stocke les types pour l'analyse sémantique | 143 | | NUM {$$ = INT;} // on stocke les types pour l'analyse sémantique |
144 | | CARACTERE {$$ = CHAR;} | 144 | | CARACTERE {$$ = CHAR;} |
145 | | IDENT '(' Arguments ')' {$$ = INT;} //tableau d'entiers uniquement | 145 | | IDENT '(' Arguments ')' {$$ = INT;} //tableau d'entiers uniquement |
146 | ; | 146 | ; |
147 | LValue: | 147 | LValue: |
148 | IDENT {lookup($<ident>1);} | 148 | IDENT {lookup($<ident>1);get_type($<ident>1);} |
149 | | IDENT '[' Exp ']' {lookup($<ident>1);} | 149 | | IDENT '[' Exp ']' {lookup($<ident>1);get_type($<ident>1);} |
150 | ; | 150 | ; |
151 | Arguments: | 151 | Arguments: |
152 | ListExp | 152 | ListExp |