File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,7 +34,14 @@ ASTExprNode getVariableExpr() throws Exception {
3434 }
3535
3636 ASTExprNode getDashExpr () throws Exception {
37- return getParantheseExpr ();
37+ ASTExprNode result = getParantheseExpr ();
38+ while (m_lexer .lookAhead ().m_type == Type .TDASH ) {
39+ Token curToken = m_lexer .lookAhead ();
40+ m_lexer .advance ();
41+ ASTExprNode operand = getParantheseExpr ();
42+ result = new ASTTDashNode (result , operand );
43+ }
44+ return result ;
3845 }
3946
4047 ASTExprNode getUnaryExpr () throws Exception {
Original file line number Diff line number Diff line change 1+ package com .compiler .ast ;
2+
3+ import com .compiler .TokenIntf ;
4+
5+ import java .io .OutputStreamWriter ;
6+
7+ public class ASTTDashNode extends ASTExprNode {
8+ ASTExprNode m_operand0 ;
9+ ASTExprNode m_operand1 ;
10+ com .compiler .TokenIntf .Type m_operator = TokenIntf .Type .TDASH ;
11+
12+ public ASTTDashNode (ASTExprNode operand0 , ASTExprNode operand1 ) {
13+ m_operand0 = operand0 ;
14+ m_operand1 = operand1 ;
15+ }
16+
17+ public int eval () {
18+ int operand0 = m_operand0 .eval ();
19+ int operand1 = m_operand1 .eval ();
20+ return (int ) Math .pow (operand0 ,operand1 );
21+ }
22+
23+ public void print (OutputStreamWriter outStream , String indent ) throws Exception {}
24+ }
Original file line number Diff line number Diff line change 1+ package com .compiler ;
2+
3+ import org .junit .Test ;
4+
5+ import static org .junit .Assert .assertEquals ;
6+
7+ public class TestTDashExpr extends TestExpressionParserBase {
8+ @ Test
9+ public void testTDash () throws Exception {
10+ assertEquals ((int ) Math .pow (16 , 2 ), evalExpression ("2^4^2" ));
11+ }
12+ }
13+
You can’t perform that action at this time.
0 commit comments