Skip to content

Commit 5d7b8da

Browse files
committed
Fix bug
1 parent e6cbbdc commit 5d7b8da

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

java_bytecode.j

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.class public test
1+
.class public java_class
22
.super java/lang/Object
33

44
.method public <init>()V
@@ -15,7 +15,31 @@ iconst_0
1515
istore_1
1616
iconst_0
1717
istore_2
18+
ldc 121
19+
tore_
20+
iconst_0
21+
istore_3
22+
ldc 122
23+
ore_
24+
iconst_0
25+
istore_4
26+
ldc 12666
27+
re_
28+
iconst_0
29+
istore_5
30+
ldc 98
31+
e_
32+
iconst_0
33+
istore_6
34+
ldc 97
35+
_
36+
iconst_0
37+
istore_7
38+
ldc 110
39+
1840
fconst_0
19-
fstore_3
41+
fstore_8
42+
ldc 0.000000
43+
not declared
2044
return
2145
.end method

java_parser.y

Lines changed: 11 additions & 4 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;
@@ -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)