GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 16(b)

Construct the LL(1) parse table

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

GATE 2001, Q16(b) Descriptive
Report issue

Parsing & Syntax Analysis

Question 16(b), GATE 2001: Start symbol E; productions E→aA | (E), A→+E | *E | ε. Terminals a,(,),+,*.
Question 16(b), GATE 2001: Start symbol E; productions E→aA | (E), A→+E | *E | ε. Terminals a,(,),+,*.
Tap to enlarge
Answer & solution

Answer: E/a→aA; E/(→(E); A/+→+E; A/*→*E; A/)→ε; A/$→ε; all other entries error. (no official key was published)

For a nonnullable right-hand side put its production under its FIRST terminals. For ε use FOLLOW(A). The complete table is:

nonterminal | a | ( | ) | + | * | $
E | E→aA | E→(E) | error | error | error | error
A | error | error | A→ε | A→+E | A→*E | A→ε

Every occupied cell has exactly one production, so this grammar is LL(1). For example, on a+a the parser selects E→aA, matches a, uses A→+E, matches +, selects E→aA, matches a, then uses A→ε at end of input. The end marker is a parser marker, not a terminal in the original alphabet.

Original paper, page 9