Вы находитесь на странице: 1из 3

CS 150 Machine Exercise 1 (60pts)

Date Due: March 16, 11:59PM (Late submissions will not be accepted)

Requirements:

1. Implementation of the Recursive-Descent Algorithm (source code)


2. Implementation of the LR Parser (source code)
3. Documentation of your source codes (DO NOT USE JAVADOCS) in PDF

Guidelines:

1. Submit your source codes at rapineda1@upd.edu.ph. Follow the email format:

[CS 150-SECTION] SURNAME-FIRSTNAME ME1

I should only be receiving at most 3 files per student. Do not compress your files to one file (zip/rar/tar/etc).

2. Source codes with compilation/runtime errors will automatically get a grade of 0 points for that problem.

3. Both source codes should be of the same programming language. (both in Java or both in Python)

4. Do NOT use any external libraries.

5. Develop your source codes and documentation with a mindset focused on HONOR and EXCELLENCE.

6. Submissions without documentations will NOT BE ACCEPTED.

7. I will only start checking after the deadline. You may submit as many times as you want, but I will only check
the latest submission.

Grammar:

1. A' -> A
2. A -> id = E
3. E -> E + T
4. E -> E - T
5. E -> T
6. T -> T * F
7. T -> T / F
8. T -> F
9. F -> ( E )
10. F -> id
11. id -> a
12. id -> b
13. id -> c

Instructions:

Given the grammar above, create a top-down parser implementing the Recursive-Descent algorithm (30pts) and
bottom-up parser using LR Parsing (30pts) in either Java or Python. Given an input string, your program must output
each step of parsing until it reaches the goal. For LR Parsing, output the stack-input-action table. If an error is
encountered, output "Syntax error". (You need to implement the lexical analyzer for you to successfully parse. Refer
to lex() in your book or the paper I gave you before). If the grammar is not valid for top -down parsing, fix the
grammar and implement the fixed grammar using RD algorithm.

LR Parse Table:

For Recursive-Descent (based from the grammar for expression ONLY):

Input: (a + b) / c

Output:

Next token is: 25 Next lexeme is (


Enter <expr>
Enter <term>
Enter <factor>
Next token is: 11 Next lexeme is a
Enter <expr>
Enter <term>
Enter <factor>
Next token is: 21 Next lexeme is +
Exit <factor>
Exit <term>
Next token is: 10 Next lexeme is b
Enter <term>
Enter <factor>
Next token is: 26 Next lexeme is )
Exit <factor>
Exit <term>
Exit <expr>
Next token is: 24 Next lexeme is /
Exit <factor>
Next token is: 11 Next lexeme is c
Enter <factor>
Next token is: -1 Next lexeme is EOF
Exit <factor>
Exit <term>
Exit <expr>

For LR Parsing (based from the grammar for expression ONLY):

Input: (a+b)/c

Output (may be per line or as one whole table):

Вам также может понравиться