0% found this document useful (0 votes)
10 views

Q1) Construct The LL (1) Parsing Table of The Following Grammar

The document discusses homework questions on programming language grammars and parsers. It contains questions about constructing LL(1) parsing tables and determining if given grammars are LL(1) or ambiguous. Example grammars and their FIRST and FOLLOW sets are provided along with the analysis of whether they are LL(1).

Uploaded by

Abdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Q1) Construct The LL (1) Parsing Table of The Following Grammar

The document discusses homework questions on programming language grammars and parsers. It contains questions about constructing LL(1) parsing tables and determining if given grammars are LL(1) or ambiguous. Example grammars and their FIRST and FOLLOW sets are provided along with the analysis of whether they are LL(1).

Uploaded by

Abdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Homework 3: Programming languages and compilers (COS 305)

Q1) Construct the LL(1) Parsing table of the following grammar:


S --> AaAb|BbBa
A --> ε
B --> ε

Q2) Check the following grammars if they are LL(1) or not?

 2.1)
o S --> aSbS | bSaS | ε
 2.2)
o S --> aABb
A --> c | ε
B --> d | ε
 2.3)
o S --> A | a
A --> a
 2.4)
o S --> aB | ε
B --> bC | ε
C --> c S | ε
 2.5)
o S --> AB
A --> a | ε
B --> b | ε
 2.6)
o S --> aSA
A--> c | ε
 2.7)
o S --> A
A --> Bb | Cd
B --> aB | ε
C --> cC | ε
 2.8)
o S --> aAa | ε
A --> abS | ε
 2.9)
o S --> iEtSS | a
o S’ --> eS | ε
o E --> b

Answer to Q1)

FIRST Sets: FOLLOW Sets:

Abdullah Abdulaziz Alsubaie - 441102593


FIRST(S) = {a, b} FOLLOW(S) = {$}
FIRST(A) = {ε} FOLLOW(A) = {a, b}
FIRST(B) = {ε} FOLLOW(B) = {a, b}
Parsing Table
Non-Terminal a b $

S AaAb BbBa

A ε ε

B ε

Answer to Q2)

Question # Grammar First & Follow LL(1)?


FIRST(S) = {a, b, ε} Ambiguous.
2.1 S --> aSbS | bSaS | ε
FOLLOW(S) = {a, b, $} NOT LL(1)

FIRST(S) = {a}
S --> aABb FIRST(A) = {c, ε}
No conflicts.
2.2 A --> c | ε FIRST(B) = {d, ε}
LL(1)
B --> d | ε FOLLOW(A) = {d, b}
FOLLOW(B) = {b}

S --> A | a FIRST(S) = {a} Conflict of ‘a’.


2.3
A --> a FIRST(A) = {a} NOT LL(1)

FIRST(S) = {a, ε}
FIRST(B) = {b, ε}
S --> aB | ε
FIRST(C) = {c, ε} No conflics.
2.4 B --> bC | ε
FOLLOW(S) = {$} LL(1)
C --> cS | ε
FOLLOW(B) = {c, $}
FOLLOW(C) = {$}

FIRST(S) = {a, b, ε}
S --> AB FIRST(A) = {a, ε}
Conflics because of ‘ε’
2.5 A --> a | ε FIRST(B) = {b, ε}
NOT LL(1)
B --> b | ε FOLLOW(A) = {b, $}
FOLLOW(B) = {$}
FIRST(S) = {a}
S --> aSA FIRST(A) = {c, ε} No conflics.
2.6
A --> c | ε FOLLOW(S) = {$} LL(1)
FOLLOW(A) = {$}
2.7 S --> A FIRST(S) = {a, c, ε} No conflics.
A --> Bb | Cd FIRST(A) = {a, c, ε} LL(1)
B --> aB | ε FIRST(B) = {a, ε}
C --> cC | ε FIRST(C) = {c, ε}
FOLLOW(S) = {$}
FOLLOW(A) = {$}
FOLLOW(B) = {b}
FOLLOW(C) = {d}
FIRST(S) = {a, ε}
S --> aAa | ε FIRST(A) = {a, ε}
2.8 Not LL(1)
A --> abS | ε FOLLOW(S) = {$}
FOLLOW(A) = {a}
FIRST(S) = {i, a}
FIRST(S') = {e, ε}
S --> iEtSS | a
FIRST(E) = {b} No conflics.
2.9 S' --> eS | ε
FOLLOW(S) = {e, $} LL(1)
E --> b
FOLLOW(S') = {i, a, e, $}
FOLLOW(E) = {t}

Parsing tables:

2.1
Non-Terminal a b $

S aSbS, bSaS bSaS ε

2.2
Non-Terminal a b c d $

S aABb

A ε, d c ε, d

B ε d

2.3
Non-Terminal a
2.4
Non-Terminal S a b c A, a $
2.5
Non-Terminal
S A aB a b a $ ε

BS AB bC AB AB ε

CA a ε cS ε ε

B b ε

2.6
Non-Terminal a c $

S aSA
A c ε

2.7
Non-Terminal a b c d $

S A A

A Bb Cd

B aB ε

C cC ε

2.8
Non-Terminal a b $

S aAa ε

A abS, ε

2.9
Non-Terminal i e t b a $

S iEtSS a

S' eS ε

E b

You might also like