
3240 Sample Test
1. Give context-free grammars that generate the following languages. In all parts, the alphabet § is {a,
b} .
(a) {w | the number of a s is greater than the number of b s}
(b) {w | the length of w is a multiple of 3}
2. Write a grammar for Boolean expressions that includes variable a , the constants 0 and 1, the operators
∧ (and), ∨ (or), ¬ (not) , and parentheses. Be sure to give ∨ a lower precedence than ∧ and ∧ a
lower precedence than ¬ , and allow repeated ¬ (such as ¬a ). Also make sure your grammar is not
ambiguous.
3. Consider the following grammar
E ( L ) | a
L E L | E
(a) Construct the DFA of LR(0) items for this grammar.
(b) Construct the SLR(1) parsing table.
4. Design a Turing Machine that will add two positive integer numbers which are represented by a
sequence of 0's. Consider the following example:
# OOOOO # OOOOO # OOOOOOOOO
num1 = 4 num2 =5 result=9
1. Give the Tape Alphabet, meaning the set of all characters appearing on the TM's tape (include any
character that you might write on the tape)
2. Design the state diagram of the Turing Machine.
5. Let's A be the language over { ( , ) } where the number of “(“ is equal to the number of “)”. Give a
deterministic PDA that will recognize the A
6. Let's A be the language over {0,1} where the 0's and the 1's can occur in any order and the number of
0's is greater that the number of 1's
1. Is language A acceptable a Non-deterministic PDA? If it is then provide a NPDA otherwise reason
why not.
2. Is A acceptable by a Turing Machine? If it is give a TM otherwise reason why not.