GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 8

Construct a predictive parsing table

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 1995 paper

GATE 1995, Q8 5 marks · Descriptive
Report issue

Parsing & Syntax Analysis

Question 8, GATE 1995: Construct the LL(1) table for productions: 1 E→−E; 2 E→(E); 3 E→V T; 4 T→−E; 5 T→ε; 6 V→id U; 7 U→(E); 8 U→ε; 9 G→E$. Here E=Expr,T=ExprTail,V=Var,U=VarTail,G=Goal; $ is the end marker.
Tap to enlarge
Answer & solution

Answer: Non-error entries: E: −→1, (→2, id→3; T: −→4, )/$→5; V: id→6; U: (→7, −/)/$→8; G: −/(/id→9. (no official key was published)

FIRST(E)={−,(,id}, FIRST(T)={−,ε}, FIRST(V)={id}, FIRST(U)={(,ε}, and FIRST(G)={−,(,id}. E can be followed by a closing parenthesis in productions 2 and 7, or by $ in production 9. Its appearances at the ends of productions 1 and 4 add no new terminals. Hence FOLLOW(E)=FOLLOW(T)={),$}. From E→VT, FOLLOW(V)={−,),$}; U is at the end of V→idU, so FOLLOW(U)={−,),$}.

Place each nonnullable production under the terminals in its right-hand FIRST set. Place each ε-production under FOLLOW of its left-hand side. The complete table, listing columns in the order −, (, id, ), $, is:
E: [1,2,3,error,error]
T: [4,error,error,5,5]
V: [error,error,6,error,error]
U: [8,7,error,8,8]
G: [9,9,9,error,error].

No cell has two productions, establishing the LL(1) property. Parentheses and the minus token are literal terminals; λ in the source denotes ε, not an input token. If $ is treated as an explicit grammar terminal, a separate meta-end marker follows it, without changing these table choices.

Original paper, page 6