

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solutions to the midterm exam for cs 164, a computer science course at the university of california, berkeley, covering regular expressions, context-free grammars, and parsing. It includes solutions to multiple-choice questions, fill-in-the-blank questions, and a programming question related to recursive descent parsing.
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Department of Electrical Engineering and Computer Sciences Computer Science Division
Prof. R. Fateman Fall, 2001
Solutions: CS 164 Midterm 1: September 26, 2001, 9:00AM
X -> T T -> 0T | 1T | epsilon
L(G) = {a1 a2 ...an | ai is in terminals(G), S==>* a1 a2 ... an, S is start(G)} Or in English.. a set of all strings of terminal symbols derived from the start symbol S using rules of G.
State Transitions Final State? 0 1 S S,T S T T yes
Solutions: CS 164 Midterm 1: September 26, 2001, 9:00AM 2
S → aS
S → b Complete writing a recursive descent parsing program parse that returns yes, given a lisp list that constitutes a sentence in L(G2). We give you two useful parts already.
(defun parse (tokens)(s)(if (empty tokens) "yes"))
(defun eat(h) (cond((equal h (car tokens))(pop tokens)) (t (error "stuck at ~s" tokens)))) ;; sample test: (parse ’(a a b))
;; answer (defun s()(case (car tokens) (a (eat ’a)(s)) (b (eat ’b) t)))
if then loop else23 >>>= 45 "hello /* world" iconst */
Run it to see the answer. It starts with ((if if (1. 2)) (then then ...) ...)
E -> TX T -> iY | oEc X-> pE | epsilon Y-> mT | epsilon \begin{verbatim}