

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!


Department of Computer Science University of San Francisco
Computer Science 414 Spring 2008
We will go over solutions on Monday, March 10th
(a) ab (b) ab* (c) (ab)*
(a) The set of all strings over {(, ), [, ]} which form balanced parenthesis. That is, (), ()(), ((()())()), [()()], and ([()]) are all in the language, but )(, (() and (] are not in the language. (b) The set of all strings over {num, +, -, *, /} which are legal binary post-fix expressions. Thus num, num num +, num num num * -, and num num - num * are all in the language, while num *, num * num, and num num num - are not in the language. Is your CFG ambiguous?
(a) Terminals = {for, to, id, :=, num, print} Non-Terminals = {S, E} Rules = (1) S → for id := E to E S (2) S → print E (3) E → id (4) E → num Start Symbol = S (b) Terminals = {a, b, c, $} Non-Terminals = {S, A, B} Rules = (1) S → ABc$ (2) A → aA (3) A → ǫ (4) B → bB (5) B → ǫ Start Symbol = S
Terminals = {num, *, +, (, ), $} Non-Terminals = {E′, E, T, F } Rules = (0) E′^ → E$ (1) E → E + T (2) E → T (3) T T * F (4) T → F (5) F → num (4) F → ( E ) Start Symbol = E′ num * + ( ) $ E T F 1 s5 s6 g2 g3 g 2 s8 s7 accept 3 s8 r(2) r(2) r(2) 4 r(4) r(4) r(4) r(4) 5 r(5) r(5) r(5) r(5) 6 s6 g11 g13 g 7 s5 s6 g10 g 8 s5 s6 g 9 r(3) r(3) r(3) r(3) 10 s8 r(1) r(1) r(1) 11 s7 s 12 r(6) r(6) r(6) r(6) Which of the following strings are successfully parsed? If a string is not successfully parsed, give the contents of the stack (both states an symbols) when parsing fails.
(a) num + num * num - num $ (b) num * num + + num $ (c) num + num * * num $ (d) num * ( num + num ) num $ (e) num + ((num * num)) $