comp4403 Java biancheng

发布时间:2024年01月15日

Due date: 15:00 Tuesday 4th April, 2023

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.

Assignment Compiler Files

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.

  • Do not use imports for external packages other than those in?java.util.*. Note that IntelliJ may offer the option of importing an external package to resolve an issue; please avoid taking this option because it will often add an erroneous import that you will not need. Such imports lead to the compilation failing in the environment in which your compiler will be assessed because that environment may not include the external libraries. Please check you are not importing external libraries before submitted.
  • You must?only?modify the files that must be submitted (see below).
  • You must?not?modify any other files because we will be testing your implementation using the existing other files with your submitted files.
  • Please do?not?reformat the files because we would like to just print the differences between the originals and the versions you hand in.
  • Please keep the length of lines in your files below?100?characters, so that we can print them sensibly.
  • Please avoid using?non-standard?characters, e.g. Chinese characters, including in the comments. Non-standard characters are not accepted by the Java compiler used to test your assignment and all comments should be readable by the person assessing your assignment.
  • Your implementation should be in Java?1.8?and Project language level 8. Set the IntelliJ preferences for the Java compiler to 1.8 (or use the "-source 1.8" option to the command line Java compiler).
  • Please remove any debugging output before your assignment is submitted because debugging output will cause your program to fail our automated testing of your assignment.
  • Either avoid using tabs or set your tabs stops to 4 spaces (this is the default for IntelliJ/Eclipse) so that your files will print sensibly.

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.

Overview

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

Syntax Changes

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).

文章来源:https://blog.csdn.net/2301_81917451/article/details/135600744
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。