In addition to simply building and evaluating an expression as in Arithmetica, you should allow the user a new command: to satisfy a boolean expression.
Your program should recognize the following expressions:
expression |
|
semantics |
|
---|---|---|---|
Constant |
|
a boolean constant |
true
T t |
Variable |
[a-zA-z0-9]+ |
an expression represented by a word (other than keywords true or false)
Note, the special symbol "current" refers to the current expression |
a
bugs q45 |
Assignment |
|
assigns an expression to a variable |
a = false
bugs = F || a a = bugs |
Unary Operator |
|
prefixes an expression
~ // logical not |
!a
-(t && a || F) !F |
Binary Operator |
|
combines two expressions into a single expression (in precedence order)
&& // logical and || // logical or |
a && b
a || 2 a || T && c |
Unary Functions |
|
a function that takes an expression as its single argument
satisfy(expr) // return if it is possible for given expression to be true |
satisfy(a)
satisfy(a && F) |
Parentheses |
|
raises an expression's precedence |
(a && b) || 3
!(bugs && t) |
Operators have the following precedence from left to right (listed from
highest to lowest):
() | parentheses |
~ | unary operators |
&&, || | logical operators |
= | assignment |