Docsity

Programming Languages - Assignment 1 | CS 4610, Assignments of Programming Languages

Toggle sidebar
bg1
Written Assignment 1
This assignment asks you to prepare written answers to questions on
regular languages and finite automata. Each of the questions has a short
answer. You may discuss the assignment with other students and work on
the problems together. However, your write-up should be your own individual
work.
Please print your name and email address on your homework!
We need this information so that we can give you credit for the assignment
and so that we can return it to you.
1. Consider the following languages over the alphabet Σ = {a, b}.
•L1: All strings that contain at least three a’s.
•L2: All strings that contain at most one b.
•L3: All strings that contain at least three a’s but at most one b.
•L4: All strings that contain no b’s.
Give a deterministic finite automaton (DFA) for the languages L1,L2,
L3and L4.
Aside: This example illustrates that regular languages are closed under
intersection and complementation. Note that L3=L1∩L2and L4=
Σ∗−L2where Σ∗is the language of all strings over the alphabet Σ.
2. Consider the following DFA over the alphabet Σ = {a, b}.
b
b b b
a
a a a
Give a one-sentence description of the language recognized by the DFA.
Write a regular expression for the same language.
3. Consider the following languages:
1
pf2

Partial preview of the text

Download Programming Languages - Assignment 1 | CS 4610 and more Assignments Programming Languages in PDF only on Docsity!

Written Assignment 1

This assignment asks you to prepare written answers to questions on regular languages and finite automata. Each of the questions has a short answer. You may discuss the assignment with other students and work on the problems together. However, your write-up should be your own individual work.

Please print your name and email address on your homework! We need this information so that we can give you credit for the assignment and so that we can return it to you.

  1. Consider the following languages over the alphabet Σ = {a, b}.
    • L 1 : All strings that contain at least three a’s.
    • L 2 : All strings that contain at most one b.
    • L 3 : All strings that contain at least three a’s but at most one b.
    • L 4 : All strings that contain no b’s.

Give a deterministic finite automaton (DFA) for the languages L 1 , L 2 , L 3 and L 4. Aside: This example illustrates that regular languages are closed under intersection and complementation. Note that L 3 = L 1 ∩ L 2 and L 4 = Σ∗^ − L 2 where Σ∗^ is the language of all strings over the alphabet Σ.

  1. Consider the following DFA over the alphabet Σ = {a, b}.

b

b (^) b (^) b

a (^) a (^) a a

Give a one-sentence description of the language recognized by the DFA. Write a regular expression for the same language.

  1. Consider the following languages:
  • L 1 is all strings over the alphabet Σ = {x, y} where either x occurs an odd number of times or y occurs an odd number of times (or both).
  • L 2 is all strings over the alphabet Σ = {x, y, z} where either x occurs an odd number of times or y occurs an odd number of times or z occurs an odd number of times (or both, or all three).

Give a non-deterministic finite automaton (NFA) for the languages L 1 and L 2. Aside: Non-deterministic finite automata are no more powerful than DFAs in terms of the languages they can describe. They can be expo- nentially more succinct than DFAs, however.

  1. Determine whether or not the following languages are regular. Explain why in one or two sentences. - L 1 is all strings over the alphabet {(, )} where the parentheses are balanced. For example, (()(())) ∈ L 1 but (() ∈/ L 1. - L 2 is all words Programming Language Pragmatics by Michael L. Scott. - L 3 is all 10-digit numbers that are prime. - L 4 is the Ocaml language (as described in its reference manual). The alphabet is the set of all tokens and the language is the set of all valid Ocaml programs. L 4 is not regular; give two reasons why. Aside: This explains why we cannot use a lexer to parse languages like Cool or Ruby or C.
  2. Give one advantage and one disadvantage of system described in Backus’ Speedcoding paper.

Don’t forget to print your name and email address on each page of your writeup.