Download CS3378 FINAL EXAM SPRING 2000 C. HAZLEWOOD 1. Sketch

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Regular expression wikipedia , lookup

Sloppy identity wikipedia , lookup

Construction grammar wikipedia , lookup

Stemming wikipedia , lookup

String (computer science) wikipedia , lookup

Controlled grammar wikipedia , lookup

Transformational grammar wikipedia , lookup

Parsing wikipedia , lookup

Probabilistic context-free grammar wikipedia , lookup

Interpretation (logic) wikipedia , lookup

Junction Grammar wikipedia , lookup

Context-free grammar wikipedia , lookup

Symbol grounding problem wikipedia , lookup

Transcript
CS3378
FINAL EXAM
SPRING 2000
C. HAZLEWOOD
1. Sketch (outline) the proof that not all functions are computable.
2. Construct a Finite-State Machine (FSM) to model the Quarter PC. Identify the states, the input
alphabet, the output alphabet, and construct a state diagram showing the transitions. The quarter PC
computer has a 1-bit accumulator and 2 single bits (m[0], m[1]) of memory. The machine’s instruction
set consists of an op-code and a one-bit memory address (0 or 1), with op-codes as follows:
opcode
action
ld b
ac <- m[b] where b= 0 or 1
ldi b
ac <- b
st b
m[b] <- ac
xb
ac <- ac xor m[b]
When the machine is powered up, the ac and both memory bits are initialized to 0. As instructions of
a (non-stored) program are executed sequentially, a panel light turns on and off to reflect the contents
of the ac.
3. Construct a regular expression that represents each of the following languages:
(a) all strings of 0’s and 1’s
(b) all strings of 0’s and 1’s with odd length
4. Convert the following NFA-λ to an NFA
5. Convert the regular expression a(a + b)∗ to an NFA-λ
6. Minimize the following DFA
7. Use the Pumping Lemma to show that the language L = {0k 10k | k ≥ 0}is not regular.
8. (Ingenuity problem.)
(a) Using the grammar from Example 1 below, show the steps to generate the string ”aa”.
(b) Using the grammar from Example 2 below , show the steps to generate the string ”baa”.
(c) Use the algorithm DFA->G to construct a grammar for the DFA below:
Explanation: Consider the following scheme to generate the strings in a language: starting from a
string consisting of a single symbol, the start symbol, and following a set of rewrite rules, we repeatedly
rewrite the string until it is in the language. The rewrite rules will not let us generate any strings
except the ones in the language. We will distinguish between terminal symbols, which appear in strings
in the language, and non-terminal symbols, which are ”helpers”. The start symbol is a non-terminal
symbol, the rewrite rules tell how to rewrite non-terminal symbols (only), and we keep rewriting until
only terminal symbols are left. This process is very much like diagramming a sentence in reverse, where
the sentence is a string in the language and the parts of speech (noun, predicate, prepositional phrase,
for example) are the non-terminal symbols. The start symbol, rewrite rules, non-terminal symbols,
and terminal symbols constitute a grammar.
Example 1. The following scheme generates strings of a’s:
sentence symbol
terminal symbols
non-terminal symbols
rewrite rules
1.
2.
Here are the rewrites to produce ”aaa”:
rewritten symbol
rule applied
S => aS => aaS => aaaS => aaa
^
^
^
^
1
1
1
2
S
a
S
S -> aS
S -> λ
Note that the decision to ”bail out” by applying rule 2 can be made (non-deterministically) at any
step, allowing us to generate all possible strings of a’s.
Example 2. The following scheme generates strings of a’s and b’s with even numbers of a’s:
sentence symbol
terminal symbols
non-terminal symbols
rewrite rules
1.
2.
3.
4.
5.
E
a,b
E,O
E -> aO
E -> bE
O -> aE
O -> bO
E -> λ
Here are the rewrites to produce ”abab”:
rewritten symbol
rule applied
E => aO => abO => abaE => ababE => abab
^
^
^
^
^
1
4
3
2
5
The algorithm below can be used to build a grammar like those above from a DFA. The resulting
grammar generates all strings that are recognized by the DFA.
Algorithm DFA->G
Suppose DFA M is given by M=(I, Q, q0, Next, F).
The grammar G is given by
the start state is q0
the set of non-terminals is Q
the set of terminals is I
The rewrite rules are constructed from the transitions:
for every transition Next(q,a) = p, add the rule q -> ap,
and, if p is a final state, add q -> lambda.
Example 3. The DFA shown below recognizes all strings of a’s and b’s that contain an odd number of
b’s.
Applying the algorithm DFA->G above results in the following grammar:
sentence symbol
terminal symbols
non-terminal symbols
rewrite rules
1.
2.
3.
4.
5.
E
a,b
E,O
E -> aE
E -> bO
O -> aO
O -> bE
O -> λ