Exercise 3.3
Problem 3.3.1
Consult the language reference manuals to determine
The sets of characters that form the input alphabet (exclude those may only appear in character strings or comments).
The lexical form of numerical constants and
The lexical form of identifiers.
for each of the following languages:
C
C++
C#
Fortran
Java
Lisp
SQL
Answer:
Actually this exercise is not that important. Since it will cost much time to search language for each language, which is not worth to do. So we will skip the question first and see whether we have extra time to fill it.
Problem 3.3.2
Describe the languages denoted by the following regular expressions:
a (a | b)* a
((ε|a)b*)*
(a|b)*a(a|b)(a|b)
a*ba*ba*ba*
(aa|bb)((ab|ba)(aa|bb)(ab|ba)(aa|bb))
Answer:
String made up by a’s and b’s and end with a.
Note that this is an arbitrary string make up by a’s and b’s. This is a little bit tricky since I firstly think it cannot form string arbitrarily due to the constraint of a.
This is string made up by a’s and b’s and the third character from last must be a.
String of a’s and b’s but with exactly three b.
String of a’s and b’s that has even number of a and b.
Problem 3.3.3
In a string of length n, how many of the following are there?
Prefixes
Suffixes
Proper prefixes
Substrings
Subsequences
Answer:
Clearly n+1.
Clearly n+1
n-1. Except the empty string and that string itself.
(n+1)n/2 + 1. Just enumerate substrings with length 1,2,3…n. And still need to count the empty string.
There are totally 2^n subsequences, which is a permutation problem.
Problem 3.3.4
Most languages are case sensiti