You are on page 1of 2

CMP 417 ASSIGNMENT

NAME: OYEGUNLE EMMANUEL


MATRIC NUMBER: 190202011
COURSE TITLE: complier construction
MCPHERSON UNIVERSITY

QUESTION 2.1: Consider the context grammar


S SS+ (rule 1)
S SS* (rule 2)
S a (rule 3)
A. Show how the string aa + a* can be generated by this grammar.
Solution
S SS* (using rule 2)
SS + S* (using rule 1)
as+ s* (using rule 2)
aa + s* (using rule 3)
aa + a* (using rule 2)
B. Construct a parse tree for the string
Solution
S

S S *

S S + a

a a
C. What language is generated by this grammar?
Solution
L = {Postfix expression consisting of digits, plus and various signs}
The language of the grammar is infinite.

2.2. What language is generated by the following grammar?


a. S 0 S1|01
L = { 0n 1n | n > =1 }
The language of the grammar is finite because it contains finite number of strings.

b. S +SS | -SS | a
L = {Prefix expression having plus and minus signs}

c. S S(S) S | ε
L = {matched brackets of arbitrary arrangement and nesting includes ε}
Therefore the language of the grammar is finite.

d. S aSbS | bSaS |ε
L = {string has the same amount of a and b, includes ε}
The language consists of infinite number of strings, therefore the language of the grammar
is infinite.

You might also like