Exercise Note: You may use the following regular expressions D, Z, and L to writ
ID: 3554096 • Letter: E
Question
Exercise
Note: You may use the following regular expressions D, Z, and L to write your answers.
D = (0 | 1 | 2 | 3 | 4 | . . . | 9), Z = (1 | 2 | 3 | 4 | . . . | 9), and L = (A | B | C | . . . | Z).
1. Give a regular expression that describes the set of identifiers consisting of the letters and digits, and that start with a letter, and end with a digit.
2. Give a regular expression that describes the set of identifiers consisting of the letters, the decimal digits, and the underscore characters, and that start with a letter, and with no consecutive underscore.
3. Give a regular expression that describes the multiples of 100.
4. Give a regular expression that describes the set of identifiers composed of letters, digits, and the underscore, that begins with a letter or the underscore, and end with a letter.
5. Give a regular expression that describes C-like fixed-decimal constants with no superfluous leading or trailing zeros. (Note that a digit is not required on either side of the decimal point). That is 0.0, .25, 30. , 123.01, and 123005.0 are legal, but 00.0, 001.000 and 0002345.100 are illegal.
6. Describe in English the language generated by the regular expression: L+ ( D | L | _(D | L) )* D.
Explanation / Answer
1. Give a regular expression that describes the set of identifiers consisting of the letters and digits, and that start with a letter, and end with a digit.
L (L | D)* D
2. Give a regular expression that describes the set of identifiers consisting of the letters, the decimal digits, and the underscore characters, and that start with a letter, and with no consecutive underscore.
L (L | D| _(L | D))*
3. Give a regular expression that describes the multiples of 100.
D(00)(0)*
4. Give a regular expression that describes the set of identifiers composed of letters, digits, and the underscore, that begins with a letter or the underscore, and end with a letter.
(L| _) ( L| D | _ )* L
5. Give a regular expression that describes C-like fixed-decimal constants with no superfluous leading or trailing zeros. (Note that a digit is not required on either side of the decimal point). That is 0.0, .25, 30. , 123.01, and 123005.0 are legal, but 00.0, 001.000 and 0002345.100 are illegal.
(ZD* . D+) | (D? . D+)
D? represents 0 or 1 occurrence of D
. Describe in English the language generated by the regular expression: L+ ( D | L | _(D | L) )* D.
Set of identifiers composed of letters, digits and underscore characters and starts with letters, ends with a digit, not having consecutive underscores.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.