Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In this example you are going to implement evaluation of logical propositions with atoms.
- The logical expressions have the following grammar:
- Prop = True | False | Not(Prop) | Atom(name) | And(Prop,Prop) | Or(Prop,Prop)
- We've given you a type definition for Prop. You'll need to define types, vtables, constructors and evaluate functions for each of the props. Have a look at the tests for details on how things should work. The constructor functions return a new proposition containing the arguments.
- For example:
- newNot(newTrue())
- Will return the equivalent of !true. And eval(newNot(newTrue()), NULL)
- will return 0.
- The eval function returns 1 if the given proposition evaluates to true in the environment, 0 otherwise.
- You'll also need to define the type Env which maps atom names to values and implement the bind and lookup functions. See the tests for how these functions are used.
- There will be quite a few warnings from the compiler. You can make some go away by casting returns to the expecting types.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement