Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS164 Fall 2007 Midterm Exam: Regular Expressions, Parsing, and Grammar, Exams of Programming Languages

The first midterm exam for cs164, a computer science course focusing on regular expressions, parsing, and grammar. The exam includes multiple-choice and problem-solving questions related to topics such as regular expressions, tokenization, cyk parser, earley parser, left-recursion elimination, and representation conversions.

Typology: Exams

2012/2013

Uploaded on 04/02/2013

shailaja_987c
shailaja_987c 🇮🇳

4.3

(31)

230 documents

1 / 9

Toggle sidebar

Related documents


Partial preview of the text

Download CS164 Fall 2007 Midterm Exam: Regular Expressions, Parsing, and Grammar and more Exams Programming Languages in PDF only on Docsity! P a g e | 1 First Midterm Exam CS164, Fall 2007 Oct 2, 2007  Please read all instructions (including these) carefully.  Write your name, login, and SID.  No electronic devices are allowed, including cell phones used as watches.  Silence your cell phones and place them in your bag.  The exam is closed book, but you may refer to one (1) page of handwritten notes.  Solutions will be graded on correctness and clarity. Each problem has a relatively simple and straightforward solution. Partial solutions will be graded for partial credit.  There are 9 pages in this exam and 5 questions, each with multiple parts. If you get stuck on a question move on and come back to it later.  You have 1 hour and 20 minutes to work on the exam.  Please write your answers in the space provided on the exam, and clearly mark your solutions. You may use the backs of the exam pages as scratch paper. Do not use any additional scratch paper. LOGIN: _______________________ NAME: _______________________ SID: _______________________ Problem Max points Points 1 17 2 24 3 20 4 15 5 24 TOTAL 100 P a g e | 2 Problem 1: Miscellaneous [XYZ points] 1) [XYZ points] Circle pairs of regular expressions that are equivalent (in that they describe the same sets of strings): a. (ab)+ (ab)*ab b. ab* (ab)* c. (a|b+) (a|(b)+) d. a+* a+ 2) [XYZ points] Tokenize the following fragments of Java programs. Each fragment contains an error but tokenization is still possible. Indicate tokenization by drawing ‘|’ characters between lexemes. a. int j = a ++ b; b. int j = a+++++b; c. int $foo ( int a ) { return 1; } 3) [XYZ points] CYK parser accepts arbitrary context-free grammars. This is because the CYK parser implicitly disambiguates these grammars. True or False 4) [XYZ points] A language is a set of strings. REGEX is the set of all languages that can be described with regular expressions and CFG is the set of all languages that can be described by context free grammars. Which relationship holds? Circle all applicable smileys. Answer: A B C D E F A REGEX is a strict subset of CFG B REGEX is a subset of CFG C REGEX is equal to CFG D REGEX is a superset of CFG E REGEX is a strict superset of CFG F None of the above 5) There are grammars that can be represented by NFAs but not by DFAs. True or False P a g e | 5 Problem 3: Left-recursion Elimination [XYZ points] This is a simplified grammar for regular expressions (we left out concatenation). R -> R '|' R | R '*' | '(' R ')' | 0 | 1 Part 1. [XYZ points] Write down the formula for eliminating left recursion. The formula should contain  and : Part 2. [XYZ points] What is  and  in the above grammar?  =  = Part 3. [XYZ points] Write a non-recursive CFG that recognizes the same language as the above grammar. P a g e | 6 Problem 4: Representation Conversions [XYZ points] Part 1. [XYZ points] Convert the following grammar to a regular expression, or concisely justify why this is not possible. Note: we do not care about the parse tree; the regular expression must represent the same set of strings as the grammar. ARITHMETIC CFG: E  A | M | 0 | 1 A  E + E M  M * M YOUR REGEX: Part 2. [XYZ points] Same problem as above but for a different grammar: Reverse Polish Notation CFG: E  A E | M E | 0 | 1 A  E E + M  E E * SOLUTION REGEX: P a g e | 7 Part 3. [XYZ points] Convert the following automaton into a regular expression. Show each step: first eliminate node 2, then node 3.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved