date: 2024-11-28
title: "Compiler-As-2"
status: DONE
author:
- AllenYGY
tags:
- Assignment
- Compiler
publish: True
Compiler-As-2
Given the set of tokens
and answer the following questions. Show the detail of each step.
Left-most derivation:
Right-most derivation:
There is only one production rule that has left recursion, which is
Eliminate the left recursions:
Due to
can be simplified as follows:
Rewrite the grammar as follows:
There are several productions that have common prefixes:
We can left factorize the grammar as follows:
And it can be simplified as follows:
Rewrite the grammar as follows:
These are terminal symbols. So, Follow(
Construct the corresponding augmented grammar
Construct the
For
For
For
For
For
For
For
For
For
For
For
For
For
For
For
For
For
For
For
For
Here is the list of sets of items.
0 | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 |
0 | |||||||||||||||
1 | |||||||||||||||
2 | |||||||||||||||
3 | |||||||||||||||
4 | |||||||||||||||
5 | 11 | ||||||||||||||
6 | |||||||||||||||
7 | |||||||||||||||
8 | |||||||||||||||
9 | |||||||||||||||
10 | |||||||||||||||
11 | |||||||||||||||
12 | |||||||||||||||
13 | |||||||||||||||
14 | |||||||||||||||
15 | |||||||||||||||
16 | |||||||||||||||
17 | |||||||||||||||
18 | |||||||||||||||
19 | |||||||||||||||
20 |
Stack | Input | Output |
---|---|---|
The grammar
For example the sentence
Obviously, the sentence
For example the sentence
Left-Most Derivation:
Right-Most Derivation: