-
How do we skip whitespace in nanoLex.mll?
See hint in http://cseweb.ucsd.edu/classes/fa14/cse130-a/parser_notes/beLexer.mll
-
In 2a do we have to check if both parts of a binary expression is int?
Yes. And raise a properly worded MLFailure exception otherwise.
-
Do we have to parse negative values?
No.
-
There is no specific constructor for Plus/Minus/Div other binary operations.
Use the Bin constructor for all of those.
-
Does the grader care about the exact text in MLFailure exceptions?.
No. Put something reasonable/understandable.
-
What does lookup do when it doesn't find a variable in the environment?.
Raise a properly worded MLFailure exception.
-
What does eval([], Var "hd") return in the extra credit part?.
Thanks to Val:
- Add
type value = ...
| Native of string
- Now if your lookups succeed, check whether it was one of the hd or tl function, and return Native("hd") and Native("tl")
- In App, deal with the case where the function expression evaluates to a native function, and run the appropriate OCaml code to execute this function
In that setting, your result should be:
# open Nano;;
# eval ([], Var "hd");;
- : Nano.value = Native "hd"
# eval ([], Let("hd", Const(0), Var "hd"));;
- : Nano.value = Int 0
-
Do we have to ensure that the then and else branch of an if have the same type as in ocaml?
Nope.