Skip to content

Commit dcbc612

Browse files
committed
Fix bug
1 parent 636bf8e commit dcbc612

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

java_lexical_analyzer.l

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ relop "=="|"!="|"<="|">="|"<"|">"
2828
"true" { return TRUE;}
2929
"false" { return FALSE;}
3030
{id} { sscanf(yytext, "%s", yylval.id); return IDENTIFIER;}
31-
{inum} { return INT_NUM;}
32-
{fnum} { return FLOAT_NUM;}
33-
{arithop} { return ARITH_OP;}
34-
{boolop} { return BOOL_OP;}
35-
{relop} { return REL_OP;}
31+
{inum} { yylval.integer = atoi(yytext); return INT_NUM;}
32+
{fnum} { yylval.floatType = atof(yytext); return FLOAT_NUM;}
33+
{arithop} { sscanf(yytext, "%s", yylval.smallString); return ARITH_OP;}
34+
{boolop} { sscanf(yytext, "%s", yylval.smallString); return BOOL_OP;}
35+
{relop} { sscanf(yytext, "%s", yylval.smallString); return REL_OP;}
3636
[\(\)\{\};=,] { return yytext[0];}
3737
\n { ++line_num;}
3838
%%

java_parser.y

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,14 @@ expression:
196196
}
197197
}
198198
|expression ARITH_OP expression {
199-
if ($1.varType == $3.varType ) {
200-
if ($1.varType == VarType::INT_TYPE)
201-
appendToCode("i" + getOperationCode($2));
202-
else //it's float
199+
if ($1.varType == $3.varType ) {
200+
cout<<"Arith "<<$2<<endl;
201+
if ($1.varType == VarType::INT_TYPE) {
202+
appendToCode("i" + getOperationCode($2));
203+
}
204+
else{ //it's float
203205
appendToCode("f" + getOperationCode($2));
206+
}
204207
}
205208
}
206209
|'(' expression ')' {$$.varType = $2.varType;}

0 commit comments

Comments
 (0)