Add operator < to calc
This commit is contained in:
parent
0ebb56eb7c
commit
6a41ea1f36
|
@ -69,6 +69,8 @@ double Binop::eval(const Variables& vars, const Functions& funs) const {
|
|||
return left / right;
|
||||
else if (m_op == "^")
|
||||
return std::pow(left, right);
|
||||
else if (m_op == "<")
|
||||
return left < right ? 1 : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ MINUS = -
|
|||
TIMES = \*
|
||||
DIVIDE = /
|
||||
EXPONENT = ^
|
||||
LT = <
|
||||
ASSIGN = =
|
||||
NUM = (0|[1-9][0-9]*)(\.[0-9]+)?
|
||||
IDENT = [a-zA-Z_][a-zA-Z0-9_]*
|
||||
|
|
|
@ -4,6 +4,7 @@ precedence:
|
|||
right "EXPONENT"
|
||||
left "TIMES" "DIVIDE"
|
||||
left "PLUS" "MINUS"
|
||||
nonassoc "LT"
|
||||
|
||||
start: <start>
|
||||
grammar:
|
||||
|
@ -27,6 +28,7 @@ grammar:
|
|||
| <expr> "TIMES" <expr> [binop]
|
||||
| <expr> "DIVIDE" <expr> [binop]
|
||||
| <expr> "EXPONENT" <expr> [binop]
|
||||
| <expr> "LT" <expr> [binop]
|
||||
| "IDENT" [expr_simple]
|
||||
| "NUM" [expr_simple]
|
||||
| "MINUS" <expr> [umin, right 1]
|
||||
|
|
|
@ -72,6 +72,9 @@ Parser::Value Parser::reduce_binop(std::deque<Token> subparts) {
|
|||
case calcParser_Symbol::T_EXPONENT:
|
||||
op = "^";
|
||||
break;
|
||||
case calcParser_Symbol::T_LT:
|
||||
op = "<";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue