This is an individual assignment which involves modifying the recursive descent compiler for the language PL0 to add a?skip?statement, a multiple assignment statement, and a case (switch) statement.
All sources for the assignment PL0 compiler are available as a1.zip (below). Please be sure to use the version for this assignment and not the one used for the tutorials or another assignment. There are differences (like the lexical tokens you need for this assignment are only defined in this version).
Please pay attention to course Blackboard announcments, and ensure you follow the course discussion board (https://edstem.org/) for any updates and further information on the assignment.
Read all the fine print below in detail?before?you start! And, most important, when you have finished implementing the assignment, come back and re-read the fine print again.
The multiple assignment statement allows a list of variables to be simultaneously assigned the values of a list of expressions. The trick is that all the expressions are evaluated before any of the assignments takes place, for example, the following multiple assignment?swaps?the values of x and y:
???x,y := y,x
The following assignment rotates the values of x, y and z:
???x,y,z := y,z,x
The following?case?statement assigns to y exactly once.
case i of
??when 2: y := 1
??when 3: y := x
??when 5: y := x*x
??default y := 42
??end
The following lexical tokens have been added to the scanner module of PL0 already.
KW_CASE | → | "case" |
KW_OF | → | "of" |
KW_WHEN | → | "when" |
KW_DEFAULT | → | "default" |
KW_SKIP | → | "skip" |
Keywords are case sensitive.
The non-terminal?Statement?in the grammar for PL0 is modified to the following Extended Backus-Naur Form (EBNF) grammar rules.
Statement | → | WhileStatement | IfStatement | CallStatement | |
Assignment | ReadStatement | WriteStatement | | ||
CompoundStatement | SkipStatement | CaseStatement |
where
SkipStatement | → | KW_SKIP |
Assignment | → | LValueList ASSIGN ConditionList |
LValueList | → | LValue { COMMA LValue } |
ConditionList | → | Condition { COMMA Condition } |
CaseStatement | → | KW_CASE Condition KW_OF { CaseBranch } [ KW_DEFAULT StatementList ] KW_END |
CaseBranch | → | KW_WHEN Constant COLON StatementList |
Note that each branch of a?case?statement contains a statement list, rather than just a single statement, and that the labels on each branch are constant expressions (defined using the existing nonterminal?Constant) and hence their values can be determined at compile time (static analysis time to be more precise).