Advertisement
ultiprosan

Assignment

May 20th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. In this example you are going to implement evaluation of logical propositions with atoms.
  2.  
  3. The logical expressions have the following grammar:
  4.  
  5. Prop = True | False | Not(Prop) | Atom(name) | And(Prop,Prop) | Or(Prop,Prop)
  6.  
  7. 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.
  8.  
  9. For example:
  10.  
  11. newNot(newTrue())
  12.  
  13. Will return the equivalent of !true. And eval(newNot(newTrue()), NULL)
  14.  
  15. will return 0.
  16.  
  17. The eval function returns 1 if the given proposition evaluates to true in the environment, 0 otherwise.
  18.  
  19. 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.
  20.  
  21. 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