File tree Expand file tree Collapse file tree
src/main/java/com/compiler Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .compiler ;
22
3+ import com .compiler .TokenIntf .Type ;
4+
35public 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 {
You can’t perform that action at this time.
0 commit comments