Mid Term
CMSC 331
Principles of Programming Languages
Omar Shehab
Name _________________________
Section _________________________
Wednesday, March 8, 2017
2:30PM - 3:45PM, Fine Arts 303
This exam is a closed-book-open-mind exam. It will be graded on the basis of correctness,
clarity, and neatness. Please show your work for partial credit. Use of electronic device is not
permitted without the permission of the instructor.
Academic Honesty
By enrolling in this course, each student assumes the responsibilities of an active participant in
UMBCs scholarly community in which everyones academic work and behavior are held to the
highest standards of honesty. Cheating, fabrication, plagiarism, and helping others to commit
these acts are all forms of academic dishonesty, and they are wrong. Academic misconduct
could result in disciplinary action that may include, but is not limited to, suspension or dismissal.
2
1. Using the following grammar, show a parse tree and a leftmost derivation for the
statement
A = A * ( B + ( C * (A + B) ) ).
Grammar:
<assign> <id> = <expr>
<id> A | B | C
<expr> <id> + <expr> | <id> * <expr> | (<expr>) | <id>
Parse tree:
Mid Term CMSC 331 NAME ___________________
3
Leftmost derivation:
Mid Term CMSC 331 NAME ___________________
4
2. Convert the following BNF grammar to EBNF.
<assign> <id> = <expr>
<id> A | B | C
<expr> <expr> + <expr> | <expr> * <expr> | (<expr>) | <id>
Mid Term CMSC 331 NAME ___________________
5
3. Given the following grammar and the right sentential form, draw a parse tree and show the
first or starting handle.
Grammar:
S AbB | bAc
A Ab | aBB
B Ac | cBb | c
Sentential form: aAcccbbc
Mid Term CMSC 331 NAME ___________________
6
4. Perform the pairwise disjointness test for the following grammar rule.
C aaA | b | caB
Mid Term CMSC 331 NAME ___________________
7
5. Remove direct left recursion from the following grammar.
<expr> <expr> + <term> | <term>
<term> <term> * <factor> | <factor>
<factor> (<expr>) | id
Mid Term CMSC 331 NAME ___________________
8
Mid Term CMSC 331 NAME ___________________
9
Mid Term CMSC 331 NAME ___________________