0% found this document useful (0 votes)
10 views5 pages

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

This document contains homework questions on LL(1) parsing. It asks the student to construct LL(1) parsing tables for various grammars and determine if grammars are LL(1) or not by analyzing their FIRST and FOLLOW sets.

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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

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

This document contains homework questions on LL(1) parsing. It asks the student to construct LL(1) parsing tables for various grammars and determine if grammars are LL(1) or not by analyzing their FIRST and FOLLOW sets.

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 PDF, TXT or read online on Scribd
You are on page 1/ 5

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
Abdullah Abdulaziz Alsubaie - 441102593
Answer to Q1)

FIRST Sets: FOLLOW Sets:


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) = {$}
FIRST(S) = {a, c, ε}
FIRST(A) = {a, c, ε}
S --> A FIRST(B) = {a, ε}
A --> Bb | Cd FIRST(C) = {c, ε} No conflics.
2.7
B --> aB | ε FOLLOW(S) = {$} LL(1)
C --> cC | ε 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

S A, a

A a
2.4
Non-Terminal a b c $

S aB ε

B bC ε

C cS ε

2.5
Non-Terminal a b $

S AB AB AB

A a ε ε

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