HW Due 9/29/2014 20 points
1) Consider the grammar
E –-> E OR T | T
T --> T and F | F
F --> not F | ( E ) | true | false
a) Construct a parse tree for sentence
not ( true or false)
Answer:
You do it
b) Show that this generates all Boolean expressions.
Answer:
First show that the grammar generates boolean expressions.
Second show that,
generate it.
given
any
Boolean
expression
this
grammar
can
FOCUS ON RIGHT MOST DERIVATIONS.
Proof:
(First).
Induction on the length of the strings derived.
Induction Hypothesis P(n): The grammar generates a string of length
<= n then its a Boolean expressions.
Let n = 1 (base case)
The only strings on length 1 are true and false. Hence
base case is true.
Let $n > 1$ assume P(n).
n+1.
Now consider a string of length
case 1. Either the string ends with a OR true
or
OR false. If this happens then the
derivation was due to the production
E --> E OR T; now clearly the string generated
by E is length (n-1), by Induction hypothesis
the string of length(n+1 is a Boolean expression
case 2. The string end with AND true or AND false.
Then the only way this could happen is
E--> T--> T AND F
Again since T derives strings of length (n-1)
and E-->T we are done.
case 3.
String ends with
).
The only way this can happen is
F--> ( E ). clearly, E derives strings
of length n-1, we are done.
Now to show the second part, use induction. That is given a string
which is Boolean expression, show by induction on the length of the
string you can derive it.
c) Is this grammar ambiguous?
NO
d) Construct a LL(1) table for this grammar. Are there any
conflicts in the table?
First(E) = First(T) = First(F) = { true, false, (, not }
Follow(E) = { OR, ),
Follow(T) = { AND, OR, ) } = Follow(F)
Note: We don't need the follows since we don't have
any ɛ derivations.
Lets number the productions:
1) E –-> E OR T
2) E--> T
3) T --> T and F
4) T--> F
5)
F --> not F
6) F--> ( E )
7) F--> true
8) F--> false
OR
AND
TRUE
FALSE
NOT
(
E
1,2
1,2
1,2
1,2
T
3,4
3,4
F
7
8
There are conflicts in the table.
3,4
5
3,4
6
)
2) 2) The following grammar generates numbers in binary notation.
C --> C 0 | A 1 | 0
A --> B 0 | C 1 | 1
B --> A 0 | B 1
Where C is the start symbol.
Construct a LL(1) table
SOL:
First ( C ) = { 0,1 }; First ( A ) = First ( B ) = { 1 }
Follow ( C ) = {ε, 0,1 };
C
A
B
Follow ( A ) = Follow ( B ) = { 0, 1}
0
1
C→ 0
C→C0
C→A1
C→C0
A → B0
A→C1
A→1
B→A0
B→B1
$
© Copyright 2026 Paperzz