Docsity

Fall 2005 Homework II: BNF Equivalence and Derivation Tree Exercises, Assignments of Programming Languages

Toggle sidebar
bg1
22C:111 — Fall 2005
Homework II
1. [15 points]
Write ordinary (i.e., pure) BNF that is equivalent to the Extended BNF below; {…}
denotes arbitrarily many, and […] denotes optional. Justify your solution.
<float> Æ <digit> {<digit>} . {<digit>} [E [+ | -] <digit> {<digit>}]
<digit> Æ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
2. [30 points]
Using the EBNF for Java (see class Web page), provide a derivation tree for each of the
following, or identify the reason it is invalid. The derivation steps from <identifier> to a
sequence of lower-case letters and digits that begins with a letter should be omitted.
(a) from <decimal numeral> derive: 2
(b) from <array access> derive: a[b=2]
(c) from <statement> derive: if (x) if (y) { } else break;
3. [30 points]
For each of the syntax diagrams below, provide an Extended BNF definition that
describes
exactly
the same language (C= {0,1}) and informally justify your answers.
0
1
0
1
0
1
0
0
0
0
A
(A)
(B)
(C)

Partial preview of the text

Download Fall 2005 Homework II: BNF Equivalence and Derivation Tree Exercises and more Assignments Programming Languages in PDF only on Docsity!

22C:111 — Fall 2005

Homework II

1. [15 points]

Write ordinary (i.e., pure) BNF that is equivalent to the Extended BNF below; {…}

denotes arbitrarily many, and […] denotes optional. Justify your solution.

Æ {}. {} [E [+ | - ] {}]

Æ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

2. [30 points]

Using the EBNF for Java (see class Web page), provide a derivation tree for each of the

following, or identify the reason it is invalid. The derivation steps from to a

sequence of lower-case letters and digits that begins with a letter should be omitted.

(a) from derive: 2

(b) from derive: a[b=2]

(c) from derive: if (x) if (y) { } else break;

3. [30 points]

For each of the syntax diagrams below, provide an Extended BNF definition that

describes exactly the same language (C= {0,1}) and informally justify your answers.

A

(A)

(B)

(C)