- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Implementation of LR Parsing Tables?
LR Parsing Tables are a two-dimensional array in which each entry represents an Action or goto entry. A programming language grammar having a large number of productions has a large number of states or items, i.e.,I0, I1 … … In.
So, due to more states, more Actions & goto entries will be filled, which requires a lot of memory. So, a two-dimensional array is not sufficient to store so many action entries, because each entry requires at least 8 bits to encode.
So, we have to use more efficient encoding than a two-dimensional array for encoding, Action & goto field.
For example, consider the Grammar.
E → E + T
E → T
T → T * F
T → (F)
F → (E)
F → id
Its Parsing Table will be
Encoding Action Field
Some rows of the Action Table are identical, i.e., they have the same action entries. Therefore, it can store multiple spaces by generating a pointer for each state into a one-dimensional array.
To access entries from an array, we can assign each terminal a sequence-wise number from 0 to n-1. This integer can be used as an offset to access a particular terminal. The space effectiveness can be managed by creating a list of pairs.
In the given Parsing Table, states 0, 4, 6, 7 have the same Action entries. They can be represented as
Symbol | Action |
---|---|
Id | s5 |
( | s4 |
any | Error |
State 1 has the list.
Symbol | Action |
---|---|
+ | s6 |
$ | accept |
any | error |
In state 2, if it can replace error entries by r2. So, r2 will occur on all entries except on *.
Symbol | Action |
---|---|
* | s7 |
any | r2 |
State 3 − It has only r4 entries & error entries. If it can replace error entries by r4 also, then all entries will be represented by r4.
Symbol | Action |
---|---|
any | r4 |
State 5, 10, 11 can be solved similarly.
State 8
Symbol | Action |
---|---|
+ | s6 |
) | s11 |
any | error |
State 9
Symbol | Action |
---|---|
* | s7 |
any | r1 |
Encoding goto Field
goto table can also be encoded by a list. List consist of a pair (Current state, Next state)
∴ Goto [Current state, A] = Next State
Column F − Column F has 10 for state 7, and all other entries are either 3 or error. We can replace the error by 3.
Current State | Next State |
---|---|
7 | 10 |
any | 3 |
Column T
Current State | Next State |
---|---|
6 | 9 |
any | 2 |
In Column E, we can choose 1 or 8 to be the default.
Current State | Next State |
---|---|
4 | 8 |
any | 1 |
So maintaining these lists will be obviously will save some space, i.e., almost 10 % less space will be taken as was taken earlier. These lists take a small amount of memory. But list Representation is slower than matrix Representation.
To Continue Learning Please Login
Login with Google