I'm new to Irony and the whole language implementation shebang, so I've been playing around with the ExpressionEvaluator sample that comes with the Irony source, which seems to (almost) suit my needs for a project I'm working on.
However, I would like it to support booleans as well, so I've added comparison operators to the list of binary operators, as such:
BinOp.Rule = ToTerm("+") | "-" | "*" | "/" | "**"
| "==" | "<=" | ">=" | "<" | ">" | "!=" | "<>"; // added comparison operators
Here's an example of what I'm trying to achieve:
x = 1
y = 2
eval = x < 2
eval2 = y < x
bool = true
bool2 = (eval == eval2)
Because of the added binary operators, it succeeds in parsing the above. However, when compiling and running the code, it fails on the last two lines.
- The
bool = true
line fails with the message: Error: Variable true not defined. At (5:8). How do I define true and false as constants? - The
bool2 = (eval == eval2)
line fails with the message: Error: Operator '==' is not defined for types System.Boolean and System.Boolean. At (6:15).
Edit: Solved both issues, see answer below.