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：codinghelp
- Email：99515681@qq.com
- Work Time：8:00-23:00

- Programhelp With ,Help With C++ Course... 2022-05-10
- Help With Data Programming,Help With C... 2022-05-10
- 5Cce2sashelp With ,Python，Java Progra... 2022-05-10
- Help With Program Programming,Help Wit... 2022-05-09
- Help With Csci 3110,Help With Java，Py... 2022-05-09
- Mth2222help With ,Help With C/C++，Pyt... 2022-05-09
- Cse3bdchelp With ,Help With Sql Progra... 2022-05-08
- Help With Cis 468,Help With Java，Pyth... 2022-05-08
- Comp Sci 4094/4194/7094 Assignment 3 D... 2022-05-07
- Cs 178: Machine Learning & Data Mining... 2022-05-07
- Data7703 Assignment 4 2022-05-07
- Data Programminghelp With ,Help With S... 2022-04-25
- Help With Ait681 Course,Help With Pyth... 2022-04-25
- Cse121l Programminghelp With ,Help Wit... 2022-04-25
- Help With Iti1120,Help With Java，C/C+... 2022-04-25
- Cmt304help With ,Help With C++，Python... 2022-04-25
- Help With Engn4528,Matlab Programmingh... 2022-04-24
- Help With Fin 2200,Help With Java，Pyt... 2022-04-24
- Bism 7255Help With ,Help With Java，Py... 2022-04-23
- Comp202help With ,Help With Java Progr... 2022-04-23

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

© 2021 www.asgnhelp.com

Programming Assignment Help！