CS 340, Fll 2014 Dec 11 th /13 th Finl Exm Nme: Note: in ll questions, the specil symol ɛ (epsilon) is used to indicte the empty string. Question 1. [5 points] Consider the following regulr expression; ( c)* For ech of the strings elow, circle it if it is in the lnguge generted y the regulr expression, nd cross it out if it is not in the lnguge generted y the regulr expression. c c c c c Question 2. [5 points] Specify regulr expression tht genertes the lnguge over the lphet {,, c} of ll strings not contining the sustring c. Exmples of strings in the lnguge: c c c Exmples of strings not in the lnguge: c c cc c c
Question 3. [5 points] Consider the following nondeterministic finite utomton (NFA): q2 q1 c q0 q4 q5 q3 For ech of the strings elow, circle it if it is in the lnguge ccepted y the NFA, nd cross it out if it isn t. c c cc cc c c c c Question 4. [10 points] Specify deterministic finite utomton (DFA) tht genertes the lnguge over the lphet {,, c} of ll strings not contining the sustring c. (See Question 2 for lists of exmple strings in the lnguge nd not in the lnguge.) In your DFA, e sure to indicte strt stte nd one or more finl sttes, nd mke sure ech trnsition specifies direction nd single input symol consumed.
Question 5. [5 points] Consider the following context-free grmmr (CFG), where P is the strt symol: P pp P qp P r For ech of the strings on the right, circle the string if is in the lnguge generted y the CFG, nd cross it out if it isn t. p q r ppr qqr prr pqrr pqqp pqqpr qq Question 6. [10 points] Specify context-free grmmr (CFG) which genertes the lnguge of ll ALists. An AList hs the following properties: It is sequence of terminl symols chosen from ( ), It egins with ( nd ends with ) It contins (etween the prentheses) comm-seprted list of 0 or more AListMemers An AListMemer is either the terminl symol or n AList. Exmples of strings in the lnguge Exmples of strings not in the lnguge: () () (, ) ((, (, (), )), ) ɛ, () ( (, )) Be sure to indicte which nonterminl symol in your grmmr is the strt symol.
Question 7. [10 points] Consider the following context-free grmmr with strt symol A, nonterminl symols A E F V N nd terminl symols ( ) λ. 1 2 A E E A E F V N F ( λ V. E ) V N 1 2 Assume tht you re writing recursive descent prser for this grmmr. Assume you hve lexer supporting peek(), next(), nd expect() opertions. (You cn ssume tht the lexer opertions re stteful, i.e., you don t hve to ssume tht you re using functionl lnguge.) Use pseudo-code to show how the following prse functions would e implemented. You don t hve to uild the prse tree, ut do show ll lexer opertions nd clls to prse functions. Hint: for prsee, think out how to use the lexer to decide whether tokens mtching n occurrence of the F, V, or N nonterminl is out to egin. () prsee() { () prsea() {
Progrmming Questions First things first: the following we pge specifies which resources you my use during the exm, nd links to the permitted resources: http://ycpcs.githu.io/cs340-fll2014/ssign/finl.html Strt y downloding the exm zipfile using the commnd wget zipfileurl where zipfileurl is the URL of the exm zipfile. Import the zipfile s n Eclipse project. You should see project clled cs340-finl. You will e editing the file src/cs340 finl/core.clj. There re four functions to implement: doule-it, doule-them, count-ll-nested, nd vec->tower. Mke sure you meet ll of the requirements of ech function: e.g., if the function is required to e til recursive, mke sure your function is til recursive. Some generl hints: (empty? s) tests whether sequence s is empty (first s) gets the first element in sequence s (second s) gets the second element in sequence s (lst s) gets the lst element in sequence s (rest s) gets sequence with ll ut the first element of sequence s [] is n empty vector (conj v elt) cretes vector which results from ppending elt onto the vector v (conj v elt1 elt2) returns vector which results from ppending elt1 nd elt2 onto the vector v (suvec v i j) returns vector with of the elements of vector v from index i (inclusive) to index j (exclusive) You cn run the commnd lein test in terminl window to run unit tests. When you re done, sumit your code using the lue up rrow icon (Sumit project) in Eclipse, or run the commnd mke sumit. Type your Mrmoset usernme nd pssword when prompted. Hve fun!