

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


This assignment asks you to prepare written answers to questions on BNF, EBNF, and Syntax Diagrams. Each of the questions has a short answer—no essays, please! You may discuss this assignment with other students and work on the problems together. However, your write-up should be your own individual work. Remember that written assignments are to be turned in in class on the due date.
D ::= a | b | c
Note that in this grammar, [, ], ’,’, (, ), ;, , , a, b, and c are terminals, whereas A, B, C, and D are non-terminals. For each of the strings listed below, indicate all the non-terminals that can generate it:
(a) (5pts) [c, (b; a)]] (b) (5pts) [[[a, b], c], a] (c) (5pts) [(a; [b, c]), [(b; [a, c])]]
::= | ::= | ::= | ::= 0 | 1 | ... | 9 ::= + | -
(a) (10pts) Convert the grammar into EBNF. (b) (10pts) Show the syntax diagram of the above EBNF.
(a) (5pts)
::= 0 0 0 1 | empty
(b) (10pts)
::= | | empty ::= 0 1 | empty ::= 0 0 1 | empty
(c) (10pts)
::= | ::= 0 1 | ::= 0 | 0 ::= 0 1 1 | ::= 1 | 1
::= if then | if then else | other ::= true | false
where other is a terminal that stands for any other kinds of statements.
(a) (10pts) This grammar is ambiguous. Give a string having two different parse trees and draw the parse trees. (b) (10pts) If we adopt the disambiguating rule (used in most languages) “match each else with the closest previous unmatched then,” write an equivalent, unambiguous grammar.
(a) (15pts) Write an algorithm for eliminating all productions containing useless symbols from a gram- mar. (b) (5pts) Apply your algorithm to the following grammar:
::= 0 | | ::= ::= 1 ::= 2
where is the start symbol.