Sunteți pe pagina 1din 8

12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.

md at master fool2fish/dragon-book-exercise-answers GitHub


https://github.com/fool2fish/dragon-book-exercise-answers/blob/master/ch03/3.3/3.3.md 1/8


fool2fish 9 months ago update
1 Contributor

Sign up Sign in
105 57
Star y Fork
fool2fish / Dragon-book-exercise-answers
PUBLIC

Q
+
@
y
y master branch: Dragon-book-exercise-answers / ch03 / 3.3 / 3.3.md _
_ File 269 lines (174 sloc) 8.078 KB
For each of the following languages
C
C + +
C #
Fortran
Java
Lisp
SQL
Query language manual to determine:
1. What forms the input alphabet of each language character sets are (which only appear in a character string or comment is not
included)?
2. What grammatical form of numeric constants for each language is?
3. What lexical form for each language identifier is?
Describe the following languages regular expressions defined:
1. a (a | b) * a
2. (( | a) b *) *
3. (A | b) * a (a | b) (a | b)
4. a * ba * ba * ba *
5. !! (Aa | bb) * ((ab | ba) (aa | bb) * (ab | ba) (aa | bb) *) *
1. String consists of a and b consisting of a beginning and ending.
2. Strings constituted by the a and b.
3. Penultimate three strings of a and b is composed of a.
4. Strings constituted by the a and b only contains 3 b.
5. A string comprising an even number and an even number of a and b is composed of b.
g Open Edit Raw Blame History Delete
3.3 Exercise
3.3.1
3.3.2
Answer
Explore Features Enterprise Blog Search or type a command This repository
12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub
https://github.com/fool2fish/dragon-book-exercise-answers/blob/master/ch03/3.3/3.3.md 2/8
Explain within a string of length n, the number of
1. Prefix
2. Suffix
3. True prefix
4. ! Substring
5. ! Subsequence
1. n + 1
2. n + 1
3. n - 1
4. C (n +1,2)
5. (i = 0, n) C (n, i)
Many languages are case-sensitive, so they can have only one language keywords written description of these keywords morpheme
regex is very simple. But, like so uh SQL language is not case sensitive. Please describe how to use regular expressions to
express case-insensitive language keywords. SQL language description given keyword "select" expression to illustrate your
thoughts.
select -> [Ss] [Ee] [Ll] [Ee] [Cc] [Tt]
! Write down the following definition of regular languages
1. Contains all five vowels lowercase strings, these strings of vowels in order of appearance
2. All lowercase letters by increasing sequence consisting dictionary string
3. Notes, / * and * string / between the and the string is not no double quotes * /
4. ! ! Unique number of all bits of the string (strings such as allowing 101, 110 but does not allow such a string)
5. ! ! A string of all the even-numbered and odd composed b
6. Collection footwork chess informal methods represented as p - k4 or kbp x qn
7. ! ! All of a and b and does not contain the substring consisting of a string of abb
8. All of a and b and does not contain sequences composed of a string of abb
1,
want -> other * a (other | a) * e (other | e) * i (other | i) * o (other | o) * u (other | u) *
other -> [bcdfghjklmnpqrstvwxyz]
2,
a * b * ... z *
3.3.3
Answer
3.3.4
Answer
3.3.5
Answer
12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub
https://github.com/fool2fish/dragon-book-exercise-answers/blob/master/ch03/3.3/3.3.md 3/8
3,
\ / \ * ([^ * "] * |" * "|. \ * + [^ /]) * \ * \ /
/ * And * / between content appears, is the closure of the three different (random combinations of strings of arbitrary length):
1. [^ * "] * : * and in addition to "all the symbols of arbitrary length string outside.
2. "*." : two string enclosed in quotation marks, it allows any symbol.
3. \ * + [^ /] : * the situation, followed by a not / symbol.
This expression also matches / ** / situation.
It should be noted that the expression implies the following constraints:
Not contain unpaired quotes
Did not consider the case of single quotes (some languages also Table strings in single quotes)
4,
want -> 0 | A 0 1 (A0 1 | 01?) * A 0 | A0?????
A -> 0 2 (02) *?
Solution process:
step1. conversion chart
step2. GNFA
step3. removing nodes 0 and simplify
12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub
https://github.com/fool2fish/dragon-book-exercise-answers/blob/master/ch03/3.3/3.3.md 4/8
step4. remove the node 2, and to simplify
step5. removing node 1, and simplify
12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub
https://github.com/fool2fish/dragon-book-exercise-answers/blob/master/ch03/3.3/3.3.md 5/8
5,
want -> (FE * G | (aa) * b) (E | FE * G)
E -> b (aa) * b
F -> a (aa) * b
G -> b (aa) * ab | a
F -> ba (aa) * b
Solution process:
step1. conversion chart
step2. GNFA
step3. removing nodes A, and simplify
step4. removing nodes D, and simplify
12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub
https://github.com/fool2fish/dragon-book-exercise-answers/blob/master/ch03/3.3/3.3.md 6/8
step5. removing node C, and simplify
8,
b * (a + b?) *
9,
b * | b * a + | b * a + ba *
The following set of characters to write the corresponding character class
1. English alphabet before 10 digits (a ~ j), including uppercase and lowercase
3.3.6
12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub
https://github.com/fool2fish/dragon-book-exercise-answers/blob/master/ch03/3.3/3.3.md 7/8
2. All lowercase consonants collection
3. Digital hexadecimal
4. Can appear in an English sentence behind legitimate character set
1. [A-Ja-j]
2. [Bcdfghjklmnpqrstvwxzy]
3. [0-9a-f]
4. [.?!]
Please note that these regular expressions in these columns characters have special meanings:
\ .? "^ $ [] * + {} | /
If you want to make these special characters, they said the senior, they must cancel their special meaning in a string, we can put
them in a length greater than or equal to 1 and the string with double quotes can cancel special meaning. For example, the regular
expression "**" ** and string matching. We can also add a backslash in front of an operator, to get the literal meaning of the
characters. Then the regular expression and string. ** ** Also match. Please write a string "\ matching regular expression.
\ "\ \
In Lex, the complement of the character class represents all characters listed in the character class outside. We will ^ at the
beginning of class to represent a character set up. Unless ^ listed in the character class, otherwise the character is not being taken
up in the character class. So [^ A-Za-z] matches any character is not uppercase and lowercase letters, [^ ^] matches any character
except ^'s. Prove that for each positive character class with a complementary set of expression, there is an equivalent without the
complement of a regular expression character class.
Prove: For each r {m, n} contain this form of expression, there is an equivalence does not contain duplicate regex operators
r {m, n} is equivalent to r (m a) r |.. r (m +1 a) r |.. ... | r (n a) r..
^ Indicates the beginning of a line can also be said to take up.
1. How to determine what it said in the end mean?
2. Whether one can always include ^ and $ regex replaced by an equivalent that does not contain these operators regular
expressions?
1. If ^ is located in parentheses, and for the first character, that is to take up, or else on behalf of the line.
Answer
3.3.7
Answer
3.3.8
3.3.9!
Answer
3.3.10!
Answer
12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub
https://github.com/fool2fish/dragon-book-exercise-answers/blob/master/ch03/3.3/3.3.md 8/8
UNIX shell command sh file name to describe a collection of operators using the table below in the file name expression. How can
use and contains only the connection and closure operators regex expressions to represent sh file name?
Expression Match Example
'S' S the string literals '\'
\ C The literal character c \ '
* Any string *. O
? Any character sort1.?
[S] s any character sort1. [cso]
SQL language support an immature patterns describe ways in which two characters have special meaning; underscore (_)
represents any character, percent sign (%) represents a string that contains zero or more characters. In addition, the programmer
can also be defined as any of the characters escape character. Suppose we already know which is the escape character, explains
how arbitrary SQL mode is represented as a regular expression.
3.3.11!
3.3.12!
Status API Training Shop Blog About 2013 GitHub , Inc.. Terms Privacy Security Contact

S-ar putea să vă placă și