program := <var_def | func_def>* <stmt>*
var_def := <typed_var> = <literal>
typed_var := <name> : <type>
func_def := def <name>([<typed_var> [, <typed_var>]*]?) [-> <type>]? : <func_body>
func_body := <var_def>* <stmt>+
stmt := <name> = <expr>
| if <expr>: <stmt>+ [elif <expr>: <stmt>+]? [else: <stmt>+]?
| while <expr>: <stmt>+
| pass
| return <expr>?
| <expr>
expr := <literal>
| <name>
| <uniop> <expr>
| <expr> <binop> <expr>
| ( <expr> )
| <name>([<expr> [, <expr>]*]?)
uniop := not | -
binop := + | - | * | // | % | == | != | <= | >= | < | > | is
literal := None
| True
| False
| <number>
type := int | bool
number := 32-bit integer literals
The grammar above is a strict subset of ChocoPy’s. Namely, the grammar above excludes:
Your compiler should have the same output and error messages as ChocoPy for programs in this subset. If you need to test out a program to check its behavior, you can do so at ChocoPy’s web site.
You will turn in two deliverables, a repository containing your implementation, and an informative README PDF.
Turn in your codebase to pa2-code
and your writeup to pa2-pdf
on Gradescope.
There is no autograder for this assignment. You are responsible for testing your implementation and ensuring that it matches the ChocoPy reference implementation’s behavior on the relevant sub-language for this PA.
Your README should include the following components:
True
/False
for boolean results rather than numeric output.By linking to specific definitions and code in your implementation, describe where and how those three variables are stored and represented throughout compilation.
f(1) + x
)If for any of the above items you don’t complete it, write a short explanation of why it was hard/what you think needs to be done in order to finish it (just a few sentences), which will help us understand your overall learning and give the best feedback.