-
Notifications
You must be signed in to change notification settings - Fork 17
Assignment1
11713020
张佳晨
When a C compiler compiles the following statement, how many tokens will it generate? [5 points]
int a3 = a * 3;It should be 7 tokens. (1 keyword, 3 id, 1 =, 1 *, and 1 termination ; )
In a string of length n(n >0), how many of the following are there?
- Prefixes [5 points]
- Proper prefixes [5 points]
- Prefixes of length m(0< m≤n) [5 points]
- Suffixes of length m(0< m≤n) [5 points]
- Proper prefixes of length m(0< m≤n) [10 points]
- Substrings [10 points]
- Subsequences [10 points]
- n + 1
- n - 1
- 1
- 1
- When m < n, it's 1. When m = n, it's 0.
- (1+n)*n/2 + 1
- 2^n
Describe the languages denoted by the following regular expressions:
- All strings consisting of
aandb. - All strings consisting of
aandb, and the last third digit isa. - Using any length of string which consists of only
ato split the stringbbb(any can be at the both end).
Write regular definitions or regular expressions for the following languages.
- All strings representing valid telephone numbers in Shenzhen. A valid telephone number contains the country code (86), a hyphen, the area code 0755, another hyphen, and eight digits where the first one cannot be zero (e.g., 86-0755-88015159). [10 points]
- All strings of a’s and b’s that start with a and end with b. [10 points]
- All strings of lowercase letters that contain the five vowels in order. [10 points]
-
86-0755-[1-9][0-9]{7} -
a(a|b)*b -
letters_ -> [b-df-hj-np-tv-z]* letters_aletters_eletters_iletters_oletters_uletters_
Suppose we have a alphabet Σ ={a,b,c}, write regular definitions to describe all strings over Σ without repeated letters.
[Hint: You may draw an NFA for the language and convert the NFA to regular definitions.]
(a(bc|cb))|(b(ac|ca))|(c(ab|ba))|(a(b|c))|(b(a|c))|(c(a|b))|(a|b|c)
Enumerate all possible strings with different with regex:
- For length 3:
(a(bc|cb))|(b(ac|ca))|(c(ab|ba)) - For length 2:
(a(b|c))|(b(a|c))|(c(a|b)) - For length 1:
(a|b|c)
