Docsity

Context Free Grammar - Programming Languages and Compilers - Exams, Exams of Programming Languages

Toggle sidebar
bg1
Fall, 2001 Prof. R. Fateman
CS 164 Midterm 1: September 26, 2001, 9:00AM
Read all instructions carefully.
There are 7 questions in the exam on 4 pages. Some questions have multiple
parts. You have 50 minutes to complete this test. The exam is closed book but you may
refer to your one page (2-sides) handwritten 8.5 by 11 inch paper.
Please write your answers in the space provided. You may use the backs of the
exam pags for scratch space. Solutions will be graded on correctness. Partial credit will
be given.
Question
Grade Out of
1 20
2 5
3 6
4 5
5 10
6 12
7 2
Total 60
pf3
pf4

Partial preview of the text

Download Context Free Grammar - Programming Languages and Compilers - Exams and more Exams Programming Languages in PDF only on Docsity!

Fall, 2001 Prof. R. Fateman

CS 164 Midterm 1: September 26, 2001, 9:00AM

Read all instructions carefully. There are 7 questions in the exam on 4 pages. Some questions have multiple parts. You have 50 minutes to complete this test. The exam is closed book but you may refer to your one page (2-sides) handwritten 8.5 by 11 inch paper. Please write your answers in the space provided. You may use the backs of the exam pags for scratch space. Solutions will be graded on correctness. Partial credit will be given.

Question Grade Out of 1 20 2 5 3 6 4 5 5 10 6 12 7 2 Total 60

State Transitions Final state? 0 1 S S, T S T T yes

  1. [20 points] Here is a table describing an automaton with 2 states. The start state is S. a. Draw a diagram of the automaton in the space to the right of the table. b. Write down a simple regular expression that describes the same language that is recognized by this automaton.

c. In the space below, draw a DFA that accepts the same language. Use as few states as possible.

d. Write a context free grammar G0 that describes the same language.

  1. [5 points] Write down a precise definition of L(G) the language generated by any context free grammar G.
  2. [6 points] Suppose grammar G1 has only one rule rewriting X, namely X ร  YZW. a. If we know that a โˆˆ First(Y), what can you conclude about First(X)?

b. Under what condition is First(W) โІ First(X)?

c. Under what condition is ฮต โˆˆ First(X)?

  1. [5 points] Here are the rules for a grammar G2 with start symbol S

S ร  aS S ร  b

i m p o c $ E TX TX X pE (^) โˆˆ โˆˆ T iY oEc Y mT (^) โˆˆ โˆˆ โˆˆ

c. Trace each stack configuration in the parsing of the input string to i c$. We have given you the first stack contents:

step stack input

  1. E $ o i c $
  2. [2 points] a. Describe any unusual piece of clothing worn on Monday Sept.24, by Prof. Fateman for the first 8 minutes of CS164 lecture.

b. How many CS164 lectures were delivered without the use of the video projector?