Example 1: Consider the Grammar
E → E + E|E * E|(E)id.
Find handles at each step for reducing the string id1 + id2 * id3 using operator Precedence Parsing.
First, Attach $ at starting and ending of string i.e., $id1 + id2 * id3 $.
Put Precedence relation between operators & symbols using Precedence Relation Table.
∴ $ <. id1. > +<. id2 >*<. id3 > $
Apply 3 steps as explained above on the string.
Example 2: Compute FIRST & LAST terminals of non-terminals E, T, and F in the following Grammar.
E → E + T| T
T → T * F | F
F → (E)| id
On seeing the production, we can judge
+ is the first terminal of E
* is the first terminal of T
(, id is the first terminals of F.
But E → T → F
∴ The First Terminal of F is contained in the First terminal of T and the First Terminal of T is contained in the First Terminal of E.
∴ First(F) = {(, id}
∴ First(T) =*∪ First (F) = {*, (, id}
First(E) = + ∪ First (T) = {+,*, (, id}
Similarly, the Last Terminals can be found.
Example 3: Consider the Grammar
E → E + T|T
T → T ∗ F|F
F → (E)| id
Perform Stack Implementation for string id + id * id using operator precedence parsing.
Precedence rules <. , .> or =. holds between the top of the stack and the current input symbol. If the top of the stack is Non-terminal, then the terminal below the top of the stack will be compared with the current input symbol.
26 videos|66 docs|30 tests
|
1. What is Computer Science Engineering (CSE)? |
2. What are the career prospects for Computer Science Engineering graduates? |
3. What are some popular programming languages that Computer Science Engineering students should learn? |
4. What skills are important for success in Computer Science Engineering? |
5. How can I prepare for the Computer Science Engineering (CSE) exam effectively? |
|
Explore Courses for Computer Science Engineering (CSE) exam
|