PA1: Decaf Program
Objective
The goal of this project is to become familiar with the Decaf programming language.
Introduction
The semester-long project for this course is to build a compiler for the Decaf language. In this project, you will implement various functions in Decaf to become familiar with the language.
You should download the reference compiler from the "Files" tab in Canvas to test your submission for this project. Invoke it with the "-i" flag to run the interpreter:
java -jar decaf-1.0.jar -i <decaf-file>
You may wish to download the starter file with function stubs: pa01.decaf
You may edit Decaf code using the editor of your choice. If you use vim, you may wish to use the syntax highlighting provided by Zamua, a previous CS 432 student.
Assignment
Implement the following functions in Decaf:
int fact(int n)
Returns the factorial ofn
(i.e., "n!
"). For example, "fact(3)
" should return6
. You may assume 1 ≤ n ≤ 10.int fib(int n)
Returns then
th Fibonacci number. For example, "fib(1)
" should return1
and "fib(4)
" should return3
. You may assume 1 ≤ n ≤ 25.bool is_prime(int n)
Returnstrue
ifn
is prime, andfalse
otherwise. Performance is not a concern, so you may use a naive algorithm. You may assume 0 ≤ n ≤ 600.int sum_nums(int len)
Returns the sum oflen
numbers from an array callednums
. For example, "sum_nums(0)
" should return0
regardless of the contents ofnums
, and "sum_nums(2)
" should return the sum of the first two numbers. You may assume the array size does not exceed 100.void sort_nums(int len)
Sortslen
numbers from an array callednums
in ascending numerical order. Sorting should be done in-place. Performance is not a concern, so you may use any sorting algorithm you wish. You may assume the array size does not exceed 100.int gcd(int a, int b)
Returns the greatest common divisor ofa
andb
. For example, "gcd(8,12)
" should return4
. Performance is not a concern, so you may use a naive algorithm. You may assume 1 ≤ a,b, ≤ 200.void draw_triangle(int base)
Draw a simple text-based triangle using hash marks ('#
'). The base of the triangle should bebase
characters long and the triangle should be oriented upwards from the base. Each level of the triangle should decrease in width by two characters per level (one on each side). Every line should end with a newline character ('\n
'), but there should be no extra whitespace above or below the triangle or on its right side. You may assume 1 ≤ base ≤ 100. Examples:base=3: # ### base=4: ## #### base=9: # ### ##### ####### #########
Reflection
One of the goals of this course is to encourage introspection and thoughtful, deliberate development processes. For this project, you will submit a short (2-3 paragraphs) reflection, answering any (or all) of the following questions as appropriate:
- Describe your design and development process. Did you use a formal software development method?
- What aspects of this project proved to be the most rewarding?
- What aspects of this project proved to be the most challenging? How did you overcome these challenges?
- How do you know your submission is correct? Briefly describe your testing regimen.
- If you had to start the project again from scratch, what would you do differently?
- What concepts from our theoretical class material or techniques from our classroom activities did you apply in this project?
- Suppose you weren’t using any of the concepts or techniques we’ve covered in class this semester; how would your solution to this project be different?
- What other areas of computer science (or CS courses you’ve taken) impacted your solution to this project?
- Do you have any other feedback about this project?
You are encouraged to include as much detail as you wish, but do not ramble. Concise answers are preferred over verbose ones. Your reflection will be graded on a five-point scale:
Insightful | 5 |
4 | |
Superficial | 3 |
2 | |
Deficient | 1 |
No submission | 0 |
FOR P1 ONLY: Some of the above questions (especially the ones about applying classroom concepts) may not be relevant for PA1; feel free to skip them for this assignment.
Submission
Please submit your .decaf
file and your plain-text reflection to the
appropriate assignments on Canvas by the due date indicated there.
Your decaf program should be self-contained and should implement all of the project specs described above. The majority of your project grade will be based on automated tests, but I also conduct a manual review of your code and may deduct points for major code style issues.
Code Reviews
One of the goals of this course is to encourage good software development practices, especially when building a large software system (such as a compiler). For this project, you will be assigned two other random students in the course. You must review their code and offer constructive feedback according to the given rubric.
Submit your review on Canvas by the Friday following this project's due date. Please submit your review as a comment (not an attached file).
Grading
Here is the grading breakdown for this project:
Automated tests | 80 |
Instructor review | 5 |
Reflection | 5 |
Peer review | 10 |
TOTAL | 100 |