Grades and deadlines
-
Initial deadline: 23:59 on Wednesday 02 September
-
How to submit: Turn in your completed
lab1.2.ymlfile, yourInterp.javafile with amainmethod, as well as a fileaichat.mdwith transcript(s) of your Gemini conversations, to the CS department submit system underSI413/lab1.2I recommend using the
clubtool to submit, by runningclub -cSI413 -plab1.2 lab1.2.yml Interp.java aichat.md -
Collaboration and AI: Recall the course policy on collaboration and AI usage. For this lab:
-
You can collaborate with freely with any classmate who is working on a different language from you, as long as that is cited and you do your own work.
-
You may use the class Gemini Gem as long as you cite where/how you used it and you turn in a complete transcript of all relevant conversations.
For the gem, if you just say “transcript” it should produce a complete block of the conversation for you to copy/paste.
-
You may not use other AI tools besides the course-specific Gemini Gem. If you think there is something useful that you aren’t able to do with the Gem, talk to your instructor!
-
-
Grading:
In this lab you will complete the following tasks:
- Choose one of the winning languages by your classmates from last week’s lab
- Write a complete interpreter for this programming language in Java
- Thoroughly and carefully test your interpreter as you write it, so that at the end you have another example program, different from the provided one, which exercises all the features of the language.
If your submission meets the requirements for each task, you will receive 10 points towards your total lab grade.
-
Resubmissions:
We will follow the same resubmission policy for all labs this semester. For any given deadline you must at leat demonstrate significant progress or you get a zero that cannot be revised. The initial deadline for this lab is the same regardless of any other pending resubmissions on previous labs. If your work is not yet up to the standard, you will receive a new deadline of one week later (up to the end of the semester) and a chance to revise for full credit.
Getting started: files
Make a new directory for this lab.
Download the file lab1.2.yml into that directory.
As you complete your work for this part, you will fill in and eventually submit this file.
You will be programming in java and submitting java source code. Start
by making an empty java file Interp.java with a main method.
Task 1: Choose a language
Here are specs for the winning languages invented by your classmates in last week’s lab. During lab, your section leader will run a “draft” to decide who works on what language.
Task 2: Writing your interpreter
Write a complete, working interpreter for your programming language, in
Java. Your main method in Interp.java should take one command-line
argument, which is a filename of a program in your language, and then
execute the code in that program.
REQUIREMENTS
Submit all the java source code required to compile and run your interpreter.
I will run your code like this:
javac *.java
java Interp some_file.txt
where some_file.txt is source code for your chosen language.
Your interpreter should only run the program specified and not print
out anything else to standard out. If you want to have a nice
“welcome” message or prompt strings, etc., be sure to print those to
System.err only.
For credit on this lab, your interpreter must work on any valid program in your chosen language.
If your interpreter identifies an error in the input program, call System.exit(7); to indicate that your interpreter correctly identified the error and didn’t just crash. In this case, it doesn’t matter what your program prints; the only requirement is that it exists with that exit code.
Tips
This is a tough assignment, but you can do it! Here’s how I would proceed:
-
Review what we did in last class to write a scanner for Java-style strings in a few different ways. Of course the string literals in your language won’t be like that, and you also need to read the rest of the code, but this should help get you started with either character-based or regex-based input.
-
Start with the simplest possible program you can think of in your target language, and try to get your interpreter just to work for that. Like maybe a program that just prints out a single string literal.
To start with, don’t worry about comments or anything else. Just try to get this simplest possible program working correctly. It should feel great!
-
Add features carefully and deliberately, one at a time. Test thoroughly as you go, and don’t move on to the next feature until you are sure your interpreter is working 100% for what you have so far.
Here is one order of features that might work well:
- Print statements and string literals, without escape sequences or anything fancy/strange inside the strings
- Allow for comments (which should be read in by your interpreter and then immediately discarded!)
- Add string concatenation
- Add string input
- Add string reversal
- If there are any escape sequences or unusual aspects to the string literals in your language, go back and get that working
- Test, test, test!
-
Keep your interpreter code organized and well-documented. If you don’t keep good organization, it will be hard to add all the features and keep your code manageable and maintainable.
-
You will end up having a bunch of small files for your test cases. Think about how you want to keep these organized. When you add a new feature to the interpreter, make sure to go back and check that you didn’t accidentally break something that used to work before!
Task 3: Example program
In the process of writing your interpreter, you should have a complete example program in your language, which is totally different from the provided one, and which shows off all the features and syntax things available in the language, including escape codes, nested expressions, comments, reversals, concatenations, inputs, and literals.
You need to turn in that example program (or write it now if you didn’t already), along with some sample correct input/output pairs that could be used to test it.
REQUIREMENTS
Fill in the complete source code (along with comments) under the
example_program field in spec.yml
Come up with at least two input/output test cases, representing sample input that could be entered at the console when your program is run, and the expected output that would be printed by your program as a result.
Fill these in under example_input_1, example_output_1, etc.
Your example program must:
-
Be original, not the same as the example program given or anything your classmates turn in
-
Demonstrate all of the capabilities that your language has in simple form, clearly demonstrating how your language is supposed to look and work.
-
Demonstrate more complex parts to show how your language’s capabilities can be nested and combined.
-
Make good use of code comments to explain clearly what your code means and what would happen if it were executed.