Skip to content

Commit 0c19940

Browse files
author
Fynn Henck
committed
Implemented getCompareExpr
1 parent a1c1ab0 commit 0c19940

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

src/main/java/com/compiler/ExpressionEvaluator.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.compiler;
22

3+
import com.compiler.TokenIntf.Type;
4+
35
public class ExpressionEvaluator implements ExpressionEvaluatorIntf {
46
private Lexer m_lexer;
57

@@ -59,7 +61,43 @@ int getShiftExpr() throws Exception {
5961
}
6062

6163
int getCompareExpr() throws Exception {
62-
return getShiftExpr();
64+
// compareExp: shiftExp (compOp shiftExp)*
65+
int input = getShiftExpr();
66+
67+
68+
while (
69+
m_lexer.lookAhead().m_type == Type.EQUAL ||
70+
m_lexer.lookAhead().m_type == Type.GREATER ||
71+
m_lexer.lookAhead().m_type == Type.LESS
72+
) {
73+
TokenIntf.Type tokenType = m_lexer.lookAhead().m_type;
74+
m_lexer.advance();
75+
switch (tokenType){
76+
case GREATER:
77+
if(input > getShiftExpr()){
78+
input = 1;
79+
}else {
80+
input = 0;
81+
}
82+
break;
83+
case LESS:
84+
if(input < getShiftExpr()){
85+
input = 1;
86+
}else {
87+
input = 0;
88+
}
89+
break;
90+
case EQUAL:
91+
if(input == getShiftExpr()){
92+
input = 1;
93+
}else {
94+
input = 0;
95+
}
96+
break;
97+
}
98+
}
99+
100+
return input;
63101
}
64102

65103
int getAndOrExpr() throws Exception {

0 commit comments

Comments
 (0)