Docsity

Practice Homework on Grammars and Parsing, Assignments of Programming Languages

Toggle sidebar
bg1
CMSC 330 practice homework on Grammars
Do NOT turn in your solutions—this homework is only for practice
1. Given the regular grammar:
S → aT | bS | a
T → aS | bT | b
(a) Give a leftmost derivation that shows S produces abaabb
(b) Draw the parse tree for abaabb
(c) Give a DFA that recognizes the same language
(d) Give a regular expression for this set.
2. Give grammars for each of the following:
(a) {a3nb2n | n>0}
(b) {a3nb2m | m,n>0}
(c) { a2nbm+ncm | m,n>0}
(d) {ambncpdq | m+n = p+q}
(d) { ambn | m≠n, m, n >0}
3. Given the grammar X → 0 X | X 1 | 01
(a) Give the parse tree for 00011111
(b) Give a regular grammar for the same language
(c) Describe the language as simply as you can as an English sentence

Partial preview of the text

Download Practice Homework on Grammars and Parsing and more Assignments Programming Languages in PDF only on Docsity!

CMSC 330 practice homework on Grammars Do NOT turn in your solutions—this homework is only for practice

  1. Given the regular grammar: S → aT | bS | a T → aS | bT | b (a) Give a leftmost derivation that shows S produces abaabb (b) Draw the parse tree for abaabb (c) Give a DFA that recognizes the same language (d) Give a regular expression for this set.
  2. Give grammars for each of the following: (a) {a 3n b 2n | n>0} (b) {a3nb2m^ | m,n>0} (c) { a 2n b m+n c m | m,n>0} (d) {ambncpdq^ | m+n = p+q} (d) { ambn^ | m≠n, m, n >0}
  3. Given the grammar X → 0 X | X 1 | 01 (a) Give the parse tree for 00011111 (b) Give a regular grammar for the same language (c) Describe the language as simply as you can as an English sentence