CMPS 260 Spring 2024
HW #6: LL(1) Parsing
Due: May 1

1. Consider the following context-free grammar (which produces a nonsense language). As you can infer from its description, its start symbol is S, its terminal alphabet Σ is {a,b,c,d,e}, and its nonterminal set V is {S, H, K, M}.

SHcK  |  e   (1) (2)
HMHc  |  K   (3) (4)
KdSe  |  λ   (5) (6)
Mb  |  abc   (7) (8)

Nonterminal
Symbol
  FIRST( )     FOLLOW( )  
S    
H
K
M
(a) For each nonterminal A, compute both FIRST(A) and FOLLOW(A). Convey that information by filling in the table to the right. Recall that

FIRST'(A) = { t ∈ Σ | A ⟹+ tα for some α }
FOLLOW(A) = { t ∈ Σ ∪ {$} | S$ ⟹+ αAtβ for some α, β }

Now, if A is nullable (i.e., A ⟹+ λ), then FIRST(A) = FIRST'(A) ∪ {λ}. Otherwise, FIRST(A) = FIRST'(A).


(b) Using the information provided by FIRST( ) and FOLLOW( ), fill in the table below to define a one-symbol-lookahead stack machine parser for the grammar. Each table entry should identify which production (if any) to apply based upon the next input symbol (i.e., the first symbol of the input string that has yet to be consumed) and the nonterminal symbol on top of the stack. (If a terminal symbol is on top of the stack, then of course it gets popped when it is matched with the next input symbol.)

top of
stack
next input symbol
  a b c d e $
S
    
    
    
    
    
    
H
K
M


(c) Implement a Recursive Descent parser for the grammar and submit it to the designated Brightspace dropbox. As a model, you can use the Java class RecDescentParser, which provides a recursive descent parser for the LL(1) grammar discussed in a course web page.