1. Homepage
  2. Programming
  3. COMP2021: Object-Oriented Programming - Group Project: A Command-Line-Based Interpreter for Simple Programs

COMP2021: Object-Oriented Programming - Group Project: A Command-Line-Based Interpreter for Simple Programs

Contact Us On WeChat
Hong KongPolyU HKCOMP2021Object-Oriented ProgrammingA Command-Line-Based Interpreter for Simple ProgramsSIMPLEJava

Group Project: A Command-Line-Based Interpreter for Simple Programs

1 Overview

The goal of this project is to develop a command-line-based interpreter for programs written in the Simple programming language. Simple is a programming language similar to Java, but it supports a very limited number of data types, operators, and statement types, and the interpreter will enable users to define and interpret Simple programs. CourseNana.COM

In a nutshell, Simple supports only two data types, namely bool and int: Values of type bool include only true and false, while values of type int range between -99999 and 99999, both inclusive. That is, calculation results of int type that are larger than 99999 or smaller than -99999 are always rounded to 99999 and -99999, respectively. In total, 16 different operators, namely %, +, -, *, /, #, ~, >, >=, <, <=, ==, !=, &&, ||, and !, and seven types of statements, namely variable definitions, skips, assignments, conditionals, loops, prints, and blocks, are supported in Simple; Each statement in a Simple program is identified by a unique label, while each variable or expression is identified by a unique name. CourseNana.COM

2 Requirements

The interpreter should provide the following capabilities: CourseNana.COM

[REQ1] (1.5 points) It should support defining variables. Command: vardef lab typ varName expRef Effect: Defines a new variable definition statement with a unique label lab. When this variable definition statement is executed, a variable with the unique name varName and of type typ is defined and initialized to the value of the expression reference expRef, where typ is either bool or int. An expression reference is either a literal, a variable name, or an expression name. Example: vardef vardef1 int x 100 Note: All variable/expression names and statement labels in Simple programs are identifiers, which 1) may contain only English letters and digits, 2) cannot start with digits, and 3) may contain at most eight characters; int, bool, true, false, and all command names (e.g., vardef and execute) are Simple keywords, and they cannot be used as variable/expression names or statement labels. CourseNana.COM

[REQ2] (1.5 points) It should support defining binary expressions. Command: binexpr expName expRef1 bop expRef2 Effect: Defines a new binary expression with a unique name expName. The new expression’s left operand is an expression reference expRef1, its binary operator is bop, and its right operand is an expression reference expRef2. The following 11 binary operators can be applied to int expression references: %, +, -, , /, >, >=, <, <=, ==, !=; The following four binary operators can be applied to bool expression references: &&, ||, ==, and !=. Example: binexpr exp1 x 20 CourseNana.COM

[REQ3] (1.5 points) It should support defining unary expressions. Command: unexpr expName uop expRef1 Effect: Defines a new unary expression with a unique name expName. The new expression’s unary operator is uop, and its operand is an expression reference expRef1. The following two unary operators can be applied to int values: # and ~ (equivalent to unary + and - in Java). The following one unary operator can be applied to bool values: !. Example: unexpr exp2 ~ exp1 CourseNana.COM

[REQ4] (1.5 points) It should support defining assignment statements. Command: assign lab varName expRef Effect: Defines a new assignment statement with a unique label lab. When this assignment statement is executed, the value of expression reference expRef will be assigned to the variable with name varName. The variable should have been defined by a vardef statement. Example: assign assign1 x exp2 CourseNana.COM

[REQ5] (1.5 points) It should support defining print statements. Command: print lab expRef Effect: Defines a new print statement with a unique label lab. When this print statement is executed, the value of the expression reference expRef will be printed between a pair of square brackets. Example: print print1 exp2 CourseNana.COM

[REQ6] (1.5 points) It should support defining skip statements. Command: skip lab Effect: Defines a new skip statement with a unique label lab. When executed, a skip statement does nothing. Example: skip skip1 CourseNana.COM

[REQ7] (1.5 points) It should support defining block statements. Command: block lab statementLab1 ... statementLabn Effect: Defines a new block statement with a unique label lab. The block statement contains a list of statements with labels statementLab1, ..., statementLabn (n > 0). When this block statement is executed, the statements in the block statement are executed in sequence. Example: block block1 assign1 skip1 CourseNana.COM

[REQ8] (1.5 points) It should support defining conditional statements. Command: if lab expRef statementLab1 statementLab2 Effect: Defines a new conditional statement with a unique label lab. When this conditional statement is executed, the statement with label statementLab1 is executed if the expression reference expRef evaluates to true; Otherwise, the statement with label statementLab2 is executed. Example: if if1 exp5 block1 print1 CourseNana.COM

[REQ9] (1.5 points) It should support defining loop statements. Command: while lab expRef statementLab1 Effect: Defines a new loop statement with a unique label lab. When this loop statement is executed, the value of the expression reference expRef is evaluated repeatedly: If it evaluates to true, the statement with label statementLab1 is executed; Otherwise, the loop terminates. Example: while while1 true block1 (note that the statement with label block1 will be repeatedly executed for ever when this while statement is executed) CourseNana.COM

[REQ10] (1.5 points) It should support defining Simple programs. Command: program programName statementLab Effect: Defines a new Simple program with a unique name programName, and the program has the statement labeled statementLab as its body. When the program is executed, the statement in its body is executed accordingly. Example: program program1 while1 CourseNana.COM

[REQ14] (3 points) It should support loading a defined Simple program from a file. Command: load path programName Effect: Loads the defined program from path and names it as programName. Example: load d:\prog1.simple program1 CourseNana.COM

[REQ15] (1 points) The user should be able to terminate the current execution of the interpreter. Command: quit Effect: Terminates the execution of the interpreter. The interpreter may be extended with the following bonus features: CourseNana.COM

[BON2] (5 points) Support for instrumenting1 Simple programs. Command: instrument programName statementLab pos expRef Effect: Prints out the value of expRef in a pair of curly braces right before/after the statement with label statementLab from the program named programName is executed, where pos should be either before or after. Note that multiple instrument commands can be used to print out multiple strings at a single statement location. Example: instrument program1 block1 after 5 will cause the interpreter to https://www.youtube.com/watch?v=VaZrulbL6Kc print out “{5}” after each time the statement labeled block1 from program named program1 is executed. CourseNana.COM

3 An Example Interaction Session with the Interpreter

A short, but complete, example interaction session with the interpreter is shown in Figure 1 to give you a concrete idea about how the interpreter is typically used. In the figure, 1) the leading > symbol on each line is the prompt character of the interpreter, 2) \ indicates the Enter key that the user presses to complete a line of input, and 3) the comments start with ‘@‘. Note that inputting a command will only cause the expression or statement being defined. The expressions and statements defined in a program will not be interpreted/executed until the execution of the program is triggered by an invocation to the execute command. For example, inputting command vardef vardef1 int x 0 will only cause a variable definition statement to be defined. The statement is not interpreted until the command execute printeven is invoked. CourseNana.COM

Figure 1: Defining and executing a Simple program printeven that prints out even numbers between 0 and 10, both inclusive. CourseNana.COM

The Simple program in Figure 1 can be rewritten into the program shown in Figure 2 using a syntax similar to Java. CourseNana.COM

int x = 0;
while(x <= 10){
    if(x % 2 == 0) then
        print x;
    else
        skip;
    x = x + 1;
}

Figure 2: Program printeven from Figure 1 written in a Java-like syntax. CourseNana.COM

Given the program printeven defined in Figure 1, Figure 3 demonstrates how the program can be debugged using corresponding commands. Moreover, if command “instrument printeven CourseNana.COM

Get Expert Help On This Assignment

Scan above qrcode with Wechat

Hong Kong代写,PolyU HK代写,COMP2021代写,Object-Oriented Programming代写,A Command-Line-Based Interpreter for Simple Programs代写,SIMPLE代写,Java代写,Hong Kong代编,PolyU HK代编,COMP2021代编,Object-Oriented Programming代编,A Command-Line-Based Interpreter for Simple Programs代编,SIMPLE代编,Java代编,Hong Kong代考,PolyU HK代考,COMP2021代考,Object-Oriented Programming代考,A Command-Line-Based Interpreter for Simple Programs代考,SIMPLE代考,Java代考,Hong Konghelp,PolyU HKhelp,COMP2021help,Object-Oriented Programminghelp,A Command-Line-Based Interpreter for Simple Programshelp,SIMPLEhelp,Javahelp,Hong Kong作业代写,PolyU HK作业代写,COMP2021作业代写,Object-Oriented Programming作业代写,A Command-Line-Based Interpreter for Simple Programs作业代写,SIMPLE作业代写,Java作业代写,Hong Kong编程代写,PolyU HK编程代写,COMP2021编程代写,Object-Oriented Programming编程代写,A Command-Line-Based Interpreter for Simple Programs编程代写,SIMPLE编程代写,Java编程代写,Hong Kongprogramming help,PolyU HKprogramming help,COMP2021programming help,Object-Oriented Programmingprogramming help,A Command-Line-Based Interpreter for Simple Programsprogramming help,SIMPLEprogramming help,Javaprogramming help,Hong Kongassignment help,PolyU HKassignment help,COMP2021assignment help,Object-Oriented Programmingassignment help,A Command-Line-Based Interpreter for Simple Programsassignment help,SIMPLEassignment help,Javaassignment help,Hong Kongsolution,PolyU HKsolution,COMP2021solution,Object-Oriented Programmingsolution,A Command-Line-Based Interpreter for Simple Programssolution,SIMPLEsolution,Javasolution,