19
19
%error-verbose
20
20
21
21
%token <id> IDENTIFIER
22
- %token INT_NUM
23
- %token FLOAT_NUM
22
+ %token <integer> INT_NUM
23
+ %token <floatType> FLOAT_NUM
24
24
%token <smallString> ARITH_OP
25
25
%token <smallString> BOOL_OP
26
26
%token <smallString> REL_OP
47
47
char id[30 ];
48
48
char smallString[20 ];
49
49
int varType;
50
+ int integer;
51
+ float floatType;
50
52
51
53
struct ExpressionType {
52
54
int varType;
@@ -154,9 +156,9 @@ assignment: IDENTIFIER '=' expression ';'{
154
156
// Check if the two sides have the same type
155
157
if (varToVarIndexAndType[$1 ].second == $3 .varType) {
156
158
if (varToVarIndexAndType[$1 ].second == VarType::INT_TYPE) {
157
- appendToCode (" istore_" +varToVarIndexAndType[$1 ].first);
159
+ appendToCode (" istore_" +to_string( varToVarIndexAndType[$1 ].first) );
158
160
} else {// Only int and float are supported
159
- appendToCode (" fstore_" +varToVarIndexAndType[$1 ].first);
161
+ appendToCode (" fstore_" +to_string( varToVarIndexAndType[$1 ].first) );
160
162
}
161
163
} else { // case when the two types aren't the same
162
164
// TODO Cast the two variables
@@ -167,8 +169,13 @@ assignment: IDENTIFIER '=' expression ';'{
167
169
};
168
170
169
171
expression :
170
- INT_NUM {$$ .varType = VarType::INT_TYPE; }
171
- | FLOAT_NUM {$$ .varType = VarType::FLOAT_TYPE ; }
172
+ INT_NUM {
173
+ $$ .varType = VarType::INT_TYPE;
174
+ appendToCode (" ldc " + to_string($1 ));
175
+ }
176
+ | FLOAT_NUM {
177
+ $$ .varType = VarType::FLOAT_TYPE ;
178
+ appendToCode (" ldc " + to_string($1 )); }
172
179
| IDENTIFIER {
173
180
// check if the identifier already exist to load or not
174
181
if (checkIfVariableExists($1 )) {
0 commit comments