ASSIGNMENT 3 SPECIFICATION1
- PARSER
General View
Due Date: prior or on April 17
th, 2021 (midnight)
• Important Note: Late submission can be accepted (since we are entering in the final
exam week).
Earnings: 15% of your course grade
Development: Activity can be done individually or in teams (only 2 students allowed).
Purpose: Development of a Parser, rewriting the grammar and adjusting the tables.
❖ Assignment #3 consists of two tasks. Task 1 is related to rewriting grammar, and
Task 2 involves the PLATYPUS 2.0 Parser implementation. At the end, you will be
able to have a rudimentary a PLATYPUS interpreter.
The main objective is to write a Recursive Descent Predictive Parser (RDPP) for the
PLATYPUS 2.0 language. You are to integrate the Parser with your existing lexical analyzer
to complete the front-end of your PLATYPUS 2.0 compiler. The implementation is broken
into two tasks.
Task 1: Modifying the Grammar (5 marks)
1.1. TASK OVERVIEW
To build a RDPP you need to modify the syntactical part of the PLATYPUS 2.0 Grammar
(The Platypus Syntactic Specification). The grammar provided for you in
PlatypusLGR_W21.pdf is an LR grammar (that is, a grammar suitable for LR parsing).
1 Adapted from resources developed by Prof. Svillen Ranev (Algonquin College, 2019)
Algonquin College – Compilers: CST8152 – Assignment 3 Specification – Fall, 2020
2
• You must transform it into an LL grammar suitable for Recursive Descent Predictive
Parsing. To accomplish that you should follow the steps outlined bellow.
• Check the PLATYPUS 2.0 Grammar for completeness and correctness.
• Eliminate the left recursion and apply left factoring where needed.
Note 1: Remembering RDPP
The RDPP means that you are creating a deterministic way to identify the sequence of tokens from
one specific grammar. To do this, it is required to solve some problems (left recursion and left
factoring) and we need to be able to detect some tokens (see the FIRST set to be used).
Some of the syntactic productions must be rewritten to make them suitable for recursive
decent predictive parsing. Do not forget that our grammar (PlatypusLGR_20F.pdf) is an LR
grammar, which must be transformed into an equivalent LL grammar.
For example, the productions of the type:
→ |
can be rearranged in a convenient for transformation form
→ |
Once you rearrange the production, you must eliminate the immediate left-recursion. The
transformation will produce the following two new productions:
→
→
In some cases, it is possible to rework the grammar to avoid some of the transformations.
This approach is often applied to production, which contain a “left-factor”. For example, the
output statement