MidtermS20Key 1
MidtermS20Key 1
Mid Term
INSTRUCTIONS:
• Do not begin or open this test until directed to do so!
• This test is closed book, closed notes, and no computer access is allowed. However, you are
allowed a 4x6 cue card with hand-written notes.
• Absolutely no collaboration is allowed. Any violations of this policy may result in a 0 grade
on the test.
• Carefully read all problems before solving them. Don’t waste time doing work that a problem
does not ask for.
• Questions may contain more than one part; make sure you answer all parts of every question.
• You must show your work where applicable.
• The test’s time limit is 100 minutes. Be sure to manage your time appropriately.
GRADING BREAKDOWN:
This study source was downloaded by 100000829408680 from CourseHero.com on 10-20-2024 17:02:38 GMT -05:00
https://www.coursehero.com/file/85867696/MidtermS20Key-1doc/
Part I. Matching – Fill in each blank with a letter for the answer that best fits the definition or completes
the sentence. Note that NO answer should be used more than once. (2x12=24 points)
1. __P___ analysis, also known as scanning is usually the first step of program compilation. It
divides a program into O_, which are the smallest meaningful units of a program.
2. LL parsers are generally referred to as _____D____ parsers. During LL parsing, they select the
appropriate grammar rule to expand based on the current nonterminal and the current input. To
facilitate this process, for each production, LL parsers pre-calculate a ____W____ set. Many LL
parser generators requires that the language be written in LL (1), where a unique production can
be identified with a single token look ahead.
3. LR parsers attempt to ___H___ the input token stream into the start symbol. Specifically, it pushes
(or___E____) each new token onto a stack, and then check to see if the symbol(s) at the top of
stack match the Right Hand Side (RHS) of a grammar rule. If a match is found, LR parser will
pop and replace the matched symbol(s) (called a ___S____ in this situation) with their
corresponding Left Hand Side (LHS) of the grammar rule.
4. The ___N___ automata recognizes the Regular Language (RL) while ___X___ automata
recognizes Context Free Language (CFL). However, neither machine is as powerful as ___K____
machine which is computationally equivalent to most computational languages.
6. To prove that a language L is not Regular, one must make use of certain characteristics of the
Regular Language, often described as a Lemma and prove by contradiction. The specific lemma
used is called ___F___ lemma.
This study source was downloaded by 100000829408680 from CourseHero.com on 10-20-2024 17:02:38 GMT -05:00
https://www.coursehero.com/file/85867696/MidtermS20Key-1doc/
Part II. Regular Language
1. Consider the finite state machine shown below:
A. What is start state, the set of accept state(s), and the alpha. (6 points)
Q0
Deterministic since every transition is defined and there is exact one for every {state, input}
C. Does the machine accept the string abcaba? Give a computation path if yes. (6 points)
q0 q0 q3 q4 q4 q1 q1
D. Give a regular expression that describes the language recognized by this machines. (4 points)
This one is probably too complicated, but here is my solution, using some extra symbols:
A a*ba*ba* | a*
B ba*c
C cA*b
2. Write the regular expression for a language on alphabet {0, 1} that contains words that contains at
least 3 pairs of 01 pattern (ex., 0111101000001). (8 points)
3
This study source was downloaded by 100000829408680 from CourseHero.com on 10-20-2024 17:02:38 GMT -05:00
https://www.coursehero.com/file/85867696/MidtermS20Key-1doc/
∑*(01) ∑* (01) ∑*(01) ∑*
3. Write the regular expression for a language on alphabet {0, 1} that contains the following four words:
101, 001, 011, 111, (8 points)
The language only contains 4 words so we could just list them all and combine with |
Or, alternatively, we could generalize it as all 4 are 3 digits ending with a 1, thus
∑∑1
This study source was downloaded by 100000829408680 from CourseHero.com on 10-20-2024 17:02:38 GMT -05:00
https://www.coursehero.com/file/85867696/MidtermS20Key-1doc/
Part III. CFL, PDA and parsing
1. Consider the following CFG for an expression grammar:
E E * E |
E-E |
(E) |
T
T a..z
Where E, T, D are non-terminals with E being the start symbol, and a through z are terminals.
A. Rewrite the grammar so that it is unambiguous with precedence () over * over -, and left
associative. Give the complete new grammar in the space below. (10 points)
EE–T|T // note that rule for – has to be listed first due to low precedence
TT*F|F
V a..z
The above grammar is NOT LL(1) as it’s left-recursive, so we have modify. Change of first two
rules were given in notes and HW3. We don’t need to change the third rule.
E T Ttail
Ftail ε | - T Ttail
T F Ftail
Ftail ε | * T Ttail
F V | (E)
V a..z
This study source was downloaded by 100000829408680 from CourseHero.com on 10-20-2024 17:02:38 GMT -05:00
https://www.coursehero.com/file/85867696/MidtermS20Key-1doc/
2. CFG - Write a CFG for the following two languages on {0, 1} (8 points each)
A. The language of Palindrome {W | W=WR}, where W could either be even or odd length.
S ε | 0 | 1 | 0S0 | 1S1
B. The language that accepts any word that is even length and its middle two symbols are the
same.
S D S D | 11 | 00
D0|1
3. Consider the following PDA which recognize the language of 0n1n where n>=0. Describe how you
would modify it so that it will accept the language of 0n1n+2 (8 points)
To accept 2 extra 1s, we could replace the q2->q3 with two trqansitions: q2q5 and q5q3
Both of which would discard one 1, i.e., 1, ε ε,
This study source was downloaded by 100000829408680 from CourseHero.com on 10-20-2024 17:02:38 GMT -05:00
https://www.coursehero.com/file/85867696/MidtermS20Key-1doc/
7
This study source was downloaded by 100000829408680 from CourseHero.com on 10-20-2024 17:02:38 GMT -05:00
https://www.coursehero.com/file/85867696/MidtermS20Key-1doc/
Powered by TCPDF (www.tcpdf.org)