Homework #5
Due: Mon, Mar 1
How to Submit
If submitting individually: Just upload your submission to the assignment in Canvas.
If submitting as part of a team:
Assign yourself to a “Group” in Canvas. Select “People” from the menu, then select the “Groups” tab. Click “Join” on a group whose name starts with “HW5”. (Sorry this list is getting obscenely long… I really wish Canvas had a better solution for this!)
You must coordinate with your team members to all join the same group. When choosing a group, please use the smallest available group number.
Do not add yourself to a group unless you have already coordinated and everyone has agreed to be in a group together.
Upload a single file named
HW5.hs
for your group for this assignment in Canvas. Only one group member needs to upload the file. Your file must contain the names and ID numbers of each member of your group in a comment at the top of your file. This is to ensure that nobody changed the composition of your group.
Notes on grading:
Your file must compile without errors in GHCi. If some of your code does not work, comment it out. If your code does not compile, the TAs will evaluate it harshly!
Do not change the existing doctest comments in the template (the lines starting with
>>>
and the results underneath). However, you are free to add your own doctest comments in addition to the ones that are there. The TAs will grade using both doctest and manual inspection of your file. If needed, they may also load your file in GHCi to run additional tests.If you can’t solve a problem, you can get partial credit by describing in comments what you tried and where you got stuck. Often times, writing this out helps you get unstuck!
Description
This is the last assignment on MiniLogo! In this assignment, you’ll be extending your semantics of MiniMiniLogo to implement the full semantics of MiniLogo.
Resources
- MiniLogo Language Description – RE-READ THIS!
- Template: HW5.template.hs
- Support file: MiniLogo.hs
- Support file: Render.hs
You should download all three of the above linked .hs
files and put them in the same directory. Rename the template to HW5.hs and enter your solutions directly in that file.
You should not edit or submit the support files as part of your solution (see exception related to the extra credit below).
You must launch GHCi from within the directory containing all of these files so that GHCi can find them when you’re working on your solution.
As always, you are free to define whatever helper functions you need (put them in HW5.hs) or use functions from the standard libraries.
Part 1: Static checker for MiniLogo programs
In this part you’ll be implementing a static checker for MiniLogo programs. Your static checker will ensure that a MiniLogo program is well formed before you try to run it. This will make our semantics much simpler since we won’t need to check for many kinds of errors in the semantics.
A well formed MiniLogo program has the following properties:
All variables must be declared before they are referenced. Variables may be declared as parameters to macros or as the index variable of a for-loop. Variables are referenced in expressions.
All macros must be declared before they are referenced. The scope of a macro definition is the entire MiniLogo program, so the body of one macro may call a later macro, and the program is still considered to be well formed.
Whenever a macro is called, it is passed exactly as many arguments as it expects. That is, the number of arguments at the call site should match the number of declared parameters in the macro definition.
This part is broken into the following tasks:
Implement the function
checkExpr
, which checks whether an expression is well formed.Implement the function
checkCmd
, which checks whether a command is well formed.Implement the function
checkBlock
, which checks whether all of the commands in a block are well formed.Implement the function
checkDef
, which checks whether a macro definition is well formed.
I have provided the function check
that uses the functions that you will implement to check an entire MiniLogo program. You should study this function closely to make sure you understand what it’s doing!
Part 2: Semantics of MiniLogo
In this part, you’ll be implementing the semantics of the full version of MiniLogo! The template file contains a detailed description of the semantic domains for each semantic function. You should also carefully read the comments in MiniLogo.hs
, which explains several of the types that you’ll be using while implementing the semantics.
This part is broken into the following tasks.
Implement
expr
, the semantic function for expressions.Complete the implementation of
cmd
, the semantic function for commands. I have provided part of the definition for you, however, you’re welcome to refactor and/or completely replace this code if you would rather implement it in a different way.
I have provided the semantics of blocks (which is almost identical to your block
function from Homework 4, just with a few extra arguments to thread through), and the semantics of programs. You should study these functions closely to make sure you understand them. In particular, make sure you understand how the macro environment works since you will need to use this while implementing macro calls in cmd
.
After you have completed the semantics of MiniLogo, you can use the draw
function in the template to run a MiniLogo program and render its output to HTML, which you can then load in your browser. To see if your semantics is working correctly, you can compare the result of running draw shebang
with this file: shebang.html
Part 3: Amazing picture (extra credit)
Use your creativity to produce a MiniLogo program that draws an amazing picture! I will show off the most amazing pictures (anonymously) in class.
To get extra credit, you must do two things:
Define the
amazing
variable in the template file. This should be the MiniLogo program that generates your amazing picture. The program that generates your amazing picture must include at least one new macro that is defined and called in your program.Submit the
.html
file produced by runningdraw amazing
. To make things easier for me, please rename this file to reflect your amazing picture. For example, if your amazing picture is the Mona Lisa, name the fileMonaLisa.html
.
The amount of extra credit awarded will be proportional to the technical impressiveness and/or artistry of the amazing picture. We expect most amazing pictures to earn between 1-5pts of extra credit, but we reserve the right to award more for exceptionally amazing pictures.
To make a truly amazing picture, you may want to define helper functions that generate parts of your MiniLogo program. You are free to define as many of these helper functions as you wish.
In the past, some students have also modified the Render.hs
file to make their pictures even more amazing. If you decide to go down the rabbit hole, please also submit your modified Render.hs
file so that we can reproduce your amazing picture.