# Problem Set 3

Due: Friday, Oct 3rd by 11:59 PM

## Problem 1

Define a context-free grammar that generates the language of all parentheses-enclosed, comma-separated lists. The alphabet of terminal symbols is

( ) , a

A list member can be an a symbol or a nested list. A list with 0 members (empty list) is allowed.

Examples of strings in the language:

()
(a)
(a,a)
((a,a),((a),a))
(a,a,a,(),a,a,a,a)
((((a))),a)

Examples of strings not in the language:

a
a,()
(a))
((a)
(aa)

## Problem 2

Define a context-free grammar that generates the language anbn, the language of n a's followed by n b's. Because n could be 0, the empty string is a member of this language.

## Problem 3

Use JFLAP to define a Turing machine that, given an input string consisting of a sequence of a, b, and c symbols, generates the reverse of the original string. Note that the output string does not have to overwrite the input string; it is acceptable to generate the output somewhere else on the tape.

For example, if the input string is

abcbabac

then when the Turing machine halts, somewhere on the tape it should have generated the output

cababcba

## Problem 4

Using the Y-combinator, define a λ-calculus function to raise a number to a power.

For example, if we use the variable pow to refer to your function, and Y to refer to the Y-combinator, then the expression

pow (Y pow) 2 3

should compute the result 8, since 23 = 8. Your function should only depend on the addition, subtraction, multiplication, and division operators, and the if / then / else construct.