design and implement a non recursive predictive Design and implement a Non-recur
ID: 3692985 • Letter: D
Question
design and implement a non recursive predictive Design and implement a Non-recursive Predictive Purser (NPP) for the following grammar: rightarrow . | rightarrow ^ | rightarrow | rightarrow 0| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Where A is an exponentiation operator (associate to right). This grammar generates statements of the form 2^2^3. 15. 20^2 for which the parser outputs 256 15 400. Solution: In order to implement this NPP. The parse table must be constructed by using first sets and follow sets. The parse table for this parser is shown as follows:Explanation / Answer
Initial Set up: Contents of the Stack: $ Start Symbol
input string: word $ ( word of token $)
Return: Exception: if and only if word is not generated by the Grammar G
Output: Produce word from Start Symbol – one token at a time
let s1 = first symbol in word$
loop until ( TOS == $)
assign TOS = Top Of the Stack
assign a = symbol denoted by s1
if ( TOS belongs to Vt || TOS == $ ) then
if ( TOS == a ) then
pop from Top of the Stack
increment s1
else raise exception
else
assign TOS --à T1 T2 T3 ….. Tn as M[TOS, a];
if production does not produce raise exception;
pop out TOS ;
push in Tn, Tn-1, Tn-2, Tn-3, ……, T3, T2, T1 into the stack;
update stack pointer accordingly
Putput TOS --à T1 T2 T3 T4 T5, ……, Tn;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.