80 likes | 143 Views
LING/C SC/PSYC 438/538. Lecture 15 Sandiway Fong. Midterm Instructions. By the end of the class 538 Answer any 5 questions 438 Answer any 4 questions Collect all answers into ONE file and email to sandiway@email.arizona.edu Good luck!. Question 1.
E N D
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong
Midterm Instructions • By the end of the class • 538 Answer any 5 questions • 438 Answer any 4 questions • Collect all answers into ONE file and email to sandiway@email.arizona.edu • Good luck!
Question 1 • Alphabet = {(,)} (set of left and right parentheses) • Language L = set of all non-empty strings with properly balanced parentheses, i.e. each left parenthesis has a properly-nested corresponding right parenthesis • Examples: • () *)( • ()()() *()(() • (()())((())()) • Give a context-free grammar for L (grammar rules in either Prolog or non-Prolog format are acceptable)
Question 2 • A grammar is ambiguous if there are two (or more) separate ways to derive the (same) string using the rules • Consider regular grammar G below Start symbol: a, alphabet = {0,1} • a --> [1], b. • b --> [0], b. • b --> [0], c. • c --> [0], b. • c --> [1], c. • c --> [1]. • Show that G is ambiguous, i.e. give an example of a string that has two distinct derivations in G • Submit both the string and its derivations • Examples: • strings 101, 1011, 1001 are members of the language generated by G
Question 3 • Consider again regular grammar G from Question 2 Start symbol: a, alphabet = {0,1} • a --> [1], b. • b --> [0], b. • b --> [0], c. • c --> [0], b. • c --> [1], c. • c --> [1]. • Construct an equivalent deterministic FSA for G • Show your steps (e.g. conversion into a NDFSA, conversion into a deterministic FSA) (diagrams okay)
Question 4 • Consider again regular grammar G from Question 2 Start symbol: a, alphabet = {0,1} • a --> [1], b. • b --> [0], b. • b --> [0], c. • c --> [0], b. • c --> [1], c. • c --> [1]. • Give an equivalent unambiguous regular grammar to G
Question 5 • Argue (convincingly) whether regular expressions (1) and (2) are equivalent or not • a(ba)* • (ab)*a
Question 6 • Define a Perl regexp as regular expressions + backreferences. • We have seen in class that Perl regexps are more powerful than regular languages, e.g. the prime number testing example. • Decide whether these languages can be described using Perl regexps. • (Submit Perl regexps for the ones you decide can be described.) • L1 = {anbn | n ≥ 1} • L2 = {anbmanbm | n,m ≥ 1} • L3 = {anbnbn | n ≥ 1}