Removed Left Recursive and Left-Factoring from the grammer:-
New Non-Terminals Added are E', T' & X'
Note: e0 used as null production.
Eleminating Left Recursion
E->T+E'
E'->T+E' | e0
Eliminating Left Factoring:-
T->idT'
T'->[X'] | e0
X'->X| e0
X->E , E | E
Symbol | First | Follow |
E | id | , id $ |
E' | id e0 | , id $ |
T | id | + |
T' | [ e0 | + |
X | id | ] |
X' | id e0 | ] |
Compute First:-
Follow
Consider following note that are terminals. E rightarrow e + t | t t rightarrow ID...
2. Consider the following context free grammar with terminals (), +, id, num, and starting symbol S. S (ST) F-id Fnum a. Compute the first and follow set of all non-terminals (use recursion or iteration, show all the steps) Show step-by-step (the parsing tree) how the following program is parsed: (num+num+id)) b.
Consider the following LL(1) grammar with terminals (, ), +, id, num, and starting symbol S. Compute the first and follow set of all the nonterminals. S → (ST) F→id
(10] Eliminate left recursion from the grammar A Ba |Aa c B Bb | Ab 1 d A Ad IB A BA ASJAE Consider the following grammar G: S'S S (S)S|e fa) (10] Construct the collection of the sets of LR(0) items (b) [5] When constructing the action table of SLR parser of G what are the rules to determine the parsing actions? That is, what is the rule for a shift action at state /? What is the rule...
10 pt) Consider the following grammar where S is the start variable » terminals: x, y, z,t,,* non-terminals: El T, F, V * start symbol: E production rules (a) (4 pt) What is the associativity of the operators+,, * and/ explain why. (b) (3 pt) What is the precedence of , and / explain why (c) (3 pt) Given a parse tree F * T 2 2 Explain how the value of the string is generated
for compiler design Compster Science epene CS 347 Compiler Design Assiznment 2 Due Date: October 28, 2018 Exercise 1 Consider the following grammar: cassign expr l <id> a) Show that this grammar is ambiguous. b) Do the necessary changes to make it unambiguous (you should consider that has more priority than -). Exercise 2 Consider the following BNF Grammar: A [B, A] | B B: CI(A; C) D::= a | b | c For each of the strings listed below,...
KITES DE INSTALA (2) Given the following grammar, E ::= E + F E ::= F: := E.id F ::= id in which E and F are non-terminal symbols, a. Fill in the following blanks to construct two leftmost derivations for the sentence id+id.id. (5 points) 80p pgitech E -> E -> b. Is this grammar ambiguous ? (1 point) N v B c iz X
Q5: (20 points) Consider the following grammars T → int | float L → L,id I id a) Perform the pairwise disjointness test for grammar (I). b) Is grammar (I) LL1 grammar? Why? Consider the grammar (II) and the input string "int id, id; ", show the content of the Stack of the Shift-Reduce algorithm. Is it conflict-free and why? c)
Question 1. (15 points) Consider the following LL (1) grammar with starting symbol S s→(ST) F → id F → num a) Compute the First and Follow sets of all non-terminals (5 points) b) Construct the LL (1) parsing table for the grammar (5 points) c) Show step-by-step (content of stack and input string, as well as the production taken) how the following string is parsed: ((20+30 + a)) (5 points)
Consider the following BNF grammar that we saw in class: EXP ::= EXP + TERM | EXP - TERM | TERM TERM ::= TERM * FACTOR | TERM / FACTOR | FACTOR FACTOR ::= ( EXP ) | DIGIT DIGIT ::= 0 | 1 | 2 | 3 (a) Translate into EBNF. (b) Draw syntax diagrams. (c) What are the two requirements on a grammar for a predictive parser to be able to...
2. To find a Chomsky normal form for the following grammar (10 points) STR T - aTbab R RIA first note that we don't need to add a new production S' Sto the grammar because s does not appear on the right hand side of any productions in the grammar. Next, since we have a A-production in the grammar R - A, so we use the technique in question #6 to remove the production. Afterward the grammar becomes SLT TR...