Download the lab zip file: lab6.zip

**(i) Using a Recursive Descent Parser**

The folder arith contains a Python implemenation of the recusrive descent arithmetic language from figure 6.24 of the textbook. It is based on the parser described in the testbook on pages 228-230. The readme file provides and example execution.

You can read more about the implementation here
.

Modify the grammar to add exponents.

```
expr -> term + expr | term
```

term -> pow * term | pow

pow -> factor ^ pow | factor

factor -> ( expr ) | number

number -> number digit | digit

In the term function, replace calls to factor() with your new power function. When you are writting power, it should call factor. This will put the power function in the correct precedent. It is higher then multiplication but lower then parenthesis.

**Hint:** The exponent 2^5 is written pow(2,5) in python.

After modifying the code, you should be able to replicate the following example

```
Hello. Type ctrl-D (End of File) to quit.
```

Enter a math expression using 0-9,*,+,()

Example: (2+3)*(4+5)

2^5

The answer is 32

3^8

The answer is 6561

(6*5)^3

The answer is 27000

**(ii) Running the Mini Language**

In class, we will review the Mini Language. During PA4 you will add new features to the language. In this exercise you will just run the mini language.

In the folder MiniPython, execute the following command

python interpreterext.py < TestInput/fib.p

You should see the following output

```
[42]
```

Running Program

Dump of Symbol Table

Name Table

answer -> 832040

n -> 30

Function Table

fib

Review the file TestInput/fib.p to determine what is being calculated.

**(iii) Lab Documents:
Lab 6 (Word),
Lab 6 (PDF)
**