首页 >
> 详细

Simple Pascal interpreter

The purpose of this assignment is to give you practice writing a parser and an interpreter for simplified Pascal. You can start this assignment with your solution to Assignment #2, or you can use Asgn02Cpp.zip.

Modify the frontend parser to include the WHILE, FOR, IF, and CASE statements of the simplified Pascal. Use the syntax diagrams and the parse trees shown in the lecture notes. Then modify the interpreter’s backend executor to execute those statements.

Make any necessary modifications to the other classes. For example, you may need to add more parse tree node types.

Suggested order

Here is a suggested order to implement the additional statements:

1.WHILE statement. It’s similar to the REPEAT statement.

2.IF statement. Handle statements with and without an ELSE part. Be sure to handle a “dangling else” correctly.

3.FOR statement. It’s a more elaborate parse tree, so build it carefully according to the parse tree in the lecture notes.

4.CASE statement. The most elaborate parse tree. Build it very carefully according to the parse tree in the lecture notes.

For each statement, first make sure your parse tree is correct by visually inspecting the tree that the -parse option prints. Then work on executing the statement.

Test input files

Here are test input files that you should run for each of the statements and the expected runtime output. You may want to create your own simpler tests before trying these. In particular, TestIf.txt has some complicated expressions that will require modifications to the expression parser and executor. Click on the links to download the files.

You can use the online Pascal compilers to verify the output of the test files. But you’ll need to add variable declarations to turn them into valid Pascal programs.

TestWhile.txt TestWhile.out.txt

PROGRAM TestCase;

BEGIN

i := 3; even := -999; odd := -999; prime := -999;

CASE i+1 OF

1: j := i;

-8: j := 8*i;

5, 7, 4: j := 574*i;

END;

write('j = '); writeln(j);

writeln;

FOR i := -5 TO 15 DO BEGIN

CASE i OF

2: BEGIN even := i; prime := i END;

-4, -2, 0, 4, 6, 8, 10, 12, 14: even := i;

-5, -3, -1, 1, 3, 5,

7, 9, 11, 13, 15: BEGIN

odd := i;

CASE i OF

2, 3, 5, 7, 11, 13: prime := i

END

END

END;

write('i ='); write(i:3);

write(', even = '); IF even <> -999 THEN write(even:3) ELSE write('...');

write(', odd = '); IF odd <> -999 THEN write(odd:3) ELSE write('...');

write(', prime = '); IF prime <> -999 THEN write(prime:3) ELSE write('...');

writeln;

even := -999; odd := -999; prime := -999

END;

writeln; writeln('Done!')

END. j = 1722

i = -5, even = ..., odd = -5, prime = ...

i = -4, even = -4, odd = ..., prime = ...

i = -3, even = ..., odd = -3, prime = ...

TestCase.out.txt i = -2, even = -2, odd = ..., prime = ...

i = -1, even = ..., odd = -1, prime = ...

i = 0, even = 0, odd = ..., prime = ...

i = 1, even = ..., odd = 1, prime = ... i = 2, even = 2, odd = ..., prime = 2 i = 3, even = ..., odd = 3, prime = 3 i = 4, even = 4, odd = ..., prime = ... i = 5, even = ..., odd = 5, prime = 5 i = 6, even = 6, odd = ..., prime = ... i = 7, even = ..., odd = 7, prime = 7 i = 8, even = 8, odd = ..., prime = ...

i = 9, even = ..., odd = 9, prime = ... i = 10, even = 10, odd = ..., prime = ... i = 11, even = ..., odd = 11, prime = 11 i = 12, even = 12, odd = ..., prime = ... i = 13, even = ..., odd = 13, prime = 13 i = 14, even = 14, odd = ..., prime = ... i = 15, even = ..., odd = 15, prime = ...

Done!

What to submit to Canvas

A zip file that contains:

All of your C++ source files and any extra input test programs you wrote.

Cut-and-paste text files of the parse trees of each of the four input test programs that were generated from the -parse command option.

Cut-and-paste text files of the runtime output of the above simple Pascal test programs that were generated from the -execute command option.

Submit to Assignment #3: Simple Pascal Interpreter

Rubric

Your submission will be graded according to these criteria:

Criteria Max points

WHILE statement

Parse tree

Runtime output 25

10

15

IF statement

Parse tree

Runtime output 25

10

15

FOR statement

Parse tree

Runtime output 25

10

15

CASE statement

Parse tree

Runtime output 25

联系我们

- QQ：99515681
- 邮箱：99515681@qq.com
- 工作时间：8:00-23:00
- 微信：codinghelp2

- Cs2461-10实验程序代做、代写java，C/C++，Python编程设 2021-03-02
- 代写program程序语言、代做python，C++课程程序、代写java编 2021-03-02
- Programming课程代做、代写c++程序语言、Algorithms编程 2021-03-02
- 代写csc1-Ua程序、代做java编程设计、Java实验编程代做 代做留学 2021-03-02
- 代做program编程语言、代写python程序、代做python设计编程 2021-03-02
- 代写data编程设计、代做python语言程序、Python课程编程代写 代 2021-03-02
- Cse 13S程序实验代做、代写c++编程、C/C++程序语言调试 代写留学 2021-03-02
- Mat136h5编程代做、C/C++程序调试、Python，Java编程设计 2021-03-01
- 代写ee425x实验编程、代做python，C++，Java程序设计 帮做c 2021-03-01
- Cscc11程序课程代做、代写python程序设计、Python编程调试 代 2021-03-01
- 代写program编程、Python语言程序调试、Python编程设计代写 2021-03-01
- 代做r语言编程|代做database|代做留学生p... 2021-03-01
- Data Structures代写、代做r编程课程、代做r程序实验 帮做ha 2021-03-01
- 代做data留学生编程、C++，Python语言代写、Java程序代做 代写 2021-03-01
- 代写aps 105编程实验、C/C++程序语言代做 代写r语言程序|代写py 2021-03-01
- Fre6831 Computational Finance 2021-02-28
- Sta141b Assignment 5 Interactive Visu... 2021-02-28
- Eecs2011a-F20 2021-02-28
- Comp-251 Final Asssessment 2021-02-28
- 代写cs1027课程程序、代做java编程语言、代写java留学生编程帮做h 2021-02-28