Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Computer Science Department
San Francisco State University
CSC 413
Assignment 3 - Modify the Parser
Due Date
Wednesday, March 30, BEFORE MIDNIGHT
Friday, April 1, before midnight, is the late submission deadline (for 75% credit)
NOTE: This deadline overlaps the start of assignment 4! Since the standard three week
deadline for this project would normally fall on spring break, I am allowing an extra week for
submission. You are expected to appropriately manage your time, and begin assignment 4
on time. No extensions will be given.
Overview
The purpose of this assignment is to continue our work in the large compiler codebase, and
extend the Compiler to handle the new tokens and production rules added to the X language
grammar.
You are provided with the code for the complete Compiler project, which will be automatically
cloned into your github repository when you begin the assignment via this assignment link. You
will need to copy your Lexer code into this project, and update to accommodate new
tokens.
Submission
Your assignment will be submitted using github. Only the “main” branch of your
repository will be graded. Late submission is determined by the last commit time on the
main branch. You are required to submit a documentation PDF named
documentation.pdf in a documentation folder at the root of your project.
Please refer to the documentation requirements posted on iLearn. Organization and
appearance of this document is critical. Please use spelling and grammar checkers -
your ability to communicate about software and technology is almost as important as
your ability to write software!
Requirements
1. Modify the Parser to accommodate the modified grammar specified below. This grammar
includes new production rules to integrate the tokens added in Assignment 2. Note that you
will need to either copy your changed code from Assignment 2 in this directory (and possibly
re-generate the associated token files), or update this code as you did in Assignment 2. In
addition, note that you may need to add additional keyword tokens!
Production Description
TYPE → ‘utf16string’ Utf16String type token
TYPE → ‘timestamp’ Timestamp type token
F → Utf16String literal
F → Timestamp literals
E → SE ‘>=’ SE GreaterEqual token
2. Remove all debug statements not required - this includes the listing of tokens from the
Assignment 2 output.
3. Create two new visitors - OffsetVisitor.java and DrawOffsetVisitor.java - to
display a tree whose children are aligned as discussed in class. The general algorithm is:
a. Visit nodes in the AST, tracking the next available X offset for the current depth, starting
at 0
b. Base case: if the node has no children, then record that node’s X offset to be the next
available offset for the current depth, update the offset, and return
c. After visiting all children, calculate the X offset for the parent - ( rightmost child’s X offset,
plus leftmost child’s X offset ), quantity divided by 2.
1) If the calculated offset is less than the next available offset for the current depth, we
must recursively shift all children by ( next available offset for the current depth -
calculated X offset ).
2) Set the current node’s offset
3) Update the next available offset for the current depth based on the final calculated
offset for the current AST
Sample Output (simple.x - note that we have removed token output)
I’ve included a version of the correct rendered output. Note that I also added some color to the nodes,
and rendered the ovals and lines with antialiasing - you need not do this (it just made for a prettier picture
for the spec).
ᐅ java compiler.Compiler simple.x
1: program { int i int j
2: i = i + j + 7
3: j = write(i)
4: }
---------------AST-------------
1: Program
2: Block
5: Decl
3: IntType
4: Id: i
8: Decl
6: IntType
7: Id: j
10: Assign
9: Id: i
14: AddOp: +
12: AddOp: +
E → SE ‘>’ SE Greater token
S → ‘if’ E ‘then’ BLOCK if statement (without else)
S → ‘switch’ ‘(‘ ‘)’ CASEBLOCK switch statement
CASEBLOCK → ‘{‘ CASESTATEMENT+
DEFAULTSTATEMENT? ‘}’
switch statement block (one or more case
statements followed by none or one default
statement)
CASESTATEMENT → ‘case’ CASELIST ‘#’ S case list (only one statement allowed per case)
CASELIST → ‘[‘ (E list ‘,’)? ‘]’ matching list for case statements
DEFAULTSTATEMENT → ‘default’ ‘#’ S default statement may only have one statement
Production Description