Skip to content

Commit 7d27e6c

Browse files
committed
2 parents eee3b4d + 636bf8e commit 7d27e6c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

java_parser.y

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
%error-verbose
2020

2121
%token<id> IDENTIFIER
22-
%token INT_NUM
23-
%token FLOAT_NUM
22+
%token<integer> INT_NUM
23+
%token<floatType> FLOAT_NUM
2424
%token<smallString> ARITH_OP
2525
%token <smallString>BOOL_OP
2626
%token <smallString>REL_OP
@@ -47,6 +47,8 @@
4747
char id[30];
4848
char smallString[20];
4949
int varType;
50+
int integer;
51+
float floatType;
5052

5153
struct ExpressionType{
5254
int varType;
@@ -154,9 +156,9 @@ assignment: IDENTIFIER '=' expression ';'{
154156
//Check if the two sides have the same type
155157
if(varToVarIndexAndType[$1].second == $3.varType) {
156158
if(varToVarIndexAndType[$1].second == VarType::INT_TYPE) {
157-
appendToCode("istore_"+varToVarIndexAndType[$1].first);
159+
appendToCode("istore_"+to_string(varToVarIndexAndType[$1].first));
158160
} else {//Only int and float are supported
159-
appendToCode("fstore_"+varToVarIndexAndType[$1].first);
161+
appendToCode("fstore_"+to_string(varToVarIndexAndType[$1].first));
160162
}
161163
} else { // case when the two types aren't the same
162164
//TODO Cast the two variables
@@ -167,8 +169,13 @@ assignment: IDENTIFIER '=' expression ';'{
167169
};
168170

169171
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)); }
172179
|IDENTIFIER {
173180
// check if the identifier already exist to load or not
174181
if(checkIfVariableExists($1)) {

0 commit comments

Comments
 (0)