Home Page > > Details

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

Contact Us(Ghostwriter Service)

- QQ：99515681
- WeChat：codinghelp2
- Email：99515681@qq.com
- Work Time：8:00-23:00

- Help With Comp30027ghostwriter Python... 2021-08-02
- Help With Csse2002/7023 Assignment 1H... 2021-08-02
- Help With Rush2ghostwriter C/C++ Assi... 2021-08-02
- Help With R Programming|Help With Spss... 2021-05-10
- Data Programminghelp With ,Ghostwriter... 2021-05-10
- Ghostwriter 31748 Programming,Help Wit... 2021-05-10
- Help With Cis 657 Programming,Ghostwri... 2021-05-10
- Com1005 Programmingghostwriter ,Help W... 2021-05-10
- Ghostwriter Sit283 Programming,Help Wi... 2021-05-09
- C++ Programminghelp With ,Ghostwriter ... 2021-05-09
- Ghostwriter 0Ccs0cse Programming,Help ... 2021-05-09
- Comp124 Programminghelp With ,Java Pro... 2021-05-09
- Comp122 Programmingghostwriter ,Help W... 2021-05-09
- Help With Ele00041i Debugjava Program... 2021-05-08
- Help With Econ 2014 Assignment 1 Man... 2021-05-08
- Help With Mast90044 Assignment 1 Thin... 2021-05-08
- Help With Cs310 Assignment 2 Hash Tab... 2021-05-08
- Help With 5Pm Debug Java Programming ... 2021-05-08
- Help With Cs544 Final Exam Preparatio... 2021-05-08
- Help With Infs7450 Social Media Analy... 2021-05-08

Contact Us - Email：99515681@qq.com WeChat：codinghelp

© 2021 www.asgnhelp.com

Programming Assignment Help！