dragon book exercise answers ch03 3.3 3.3

Upload: yasir-alam

Post on 10-Feb-2018

385 views

Category:

Documents


2 download

TRANSCRIPT

  • 7/22/2019 Dragon Book Exercise Answers Ch03 3.3 3.3

    1/8

    12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub

    https://g ithub.com/fool2fish/drag on-book-exercise-answers/blob/master/ch03/3.3/3.3.md

    fool2fish 9 months ago update

    1 Contributor

    Sign up Sign in

    105 57Star Forkfool2fish/ Dragon-book-exercise-answersIC

    master 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 consis ts 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 compris ing an even number and an even number of a and b is composed of b.

    Open Raw Blame History

    3.3 Exercise

    3.3.1

    3.3.2

    Answer

    Explore Features Enterprise BlogSearch or type a com mandThis repository

    https://github.com/fool2fishhttps://github.com/fool2fish/dragon-book-exercise-answershttps://github.com/https://github.com/bloghttps://enterprise.github.com/https://github.com/featureshttps://github.com/explorehttps://github.com/fool2fish/dragon-book-exercise-answers/commits/master/ch03/3.3/3.3.mdhttps://github.com/fool2fish/dragon-book-exercise-answers/blame/master/ch03/3.3/3.3.mdhttps://github.com/fool2fish/dragon-book-exercise-answers/raw/master/ch03/3.3/3.3.mdhttp://windows.github.com/https://github.com/fool2fish/dragon-book-exercise-answers/tree/master/ch03/3.3https://github.com/fool2fish/dragon-book-exercise-answers/tree/master/ch03https://github.com/fool2fish/dragon-book-exercise-answershttps://github.com/fool2fish/dragon-book-exercise-answers/networkhttps://github.com/fool2fish/dragon-book-exercise-answers/graphshttps://github.com/fool2fish/dragon-book-exercise-answers/pulsehttps://github.com/fool2fish/dragon-book-exercise-answers/pullshttps://github.com/fool2fish/dragon-book-exercise-answers/issueshttps://github.com/fool2fish/dragon-book-exercise-answershttps://github.com/fool2fish/dragon-book-exercise-answershttps://github.com/fool2fishhttps://github.com/login?return_to=%2Ffool2fish%2Fdragon-book-exercise-answershttps://github.com/login?return_to=%2Ffool2fish%2Fdragon-book-exercise-answershttps://github.com/fool2fish/dragon-book-exercise-answers/networkhttps://github.com/fool2fish/dragon-book-exercise-answers/stargazershttps://github.com/login?return_to=%2Ffool2fish%2Fdragon-book-exercise-answers%2Ftree%2Fmaster%2Fch03https://github.com/joinhttps://github.com/https://github.com/fool2fish/dragon-book-exercise-answers/commit/242f2365874802ce34b8e875e368612f6db077e5https://github.com/fool2fishhttp://-/?-
  • 7/22/2019 Dragon Book Exercise Answers Ch03 3.3 3.3

    2/8

    12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub

    https://g ithub.com/fool2fish/drag on-book-exercise-answers/blob/master/ch03/3.3/3.3.md

    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

  • 7/22/2019 Dragon Book Exercise Answers Ch03 3.3 3.3

    3/8

    12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub

    https://g ithub.com/fool2fish/drag on-book-exercise-answers/blob/master/ch03/3.3/3.3.md

    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

    https://raw.github.com/fool2fish/dragon-book-practice-answer/master/ch03/3.3/assets/3.3.5-4-1.gifhttps://raw.github.com/fool2fish/dragon-book-practice-answer/master/ch03/3.3/assets/3.3.5-4.gif
  • 7/22/2019 Dragon Book Exercise Answers Ch03 3.3 3.3

    4/8

    12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub

    https://g ithub.com/fool2fish/drag on-book-exercise-answers/blob/master/ch03/3.3/3.3.md

    step4. remove the node 2, and to simplify

    step5. removing node 1, and simplify

    https://raw.github.com/fool2fish/dragon-book-practice-answer/master/ch03/3.3/assets/3.3.5-4-3.gifhttps://raw.github.com/fool2fish/dragon-book-practice-answer/master/ch03/3.3/assets/3.3.5-4-2.gif
  • 7/22/2019 Dragon Book Exercise Answers Ch03 3.3 3.3

    5/8

    12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub

    https://g ithub.com/fool2fish/drag on-book-exercise-answers/blob/master/ch03/3.3/3.3.md

    5,

    want -> (FE * G | (aa) * b) (E | FE * G)

    E -> b (aa) * b

    F -> a (aa) * b

    G -> b (aa) * ab | aF -> ba (aa) * b

    Solution process:

    step1. conversion chart

    step2. GNFA

    step3. removing nodes A, and simplify

    step4. removing nodes D, and simplify

    https://raw.github.com/fool2fish/dragon-book-practice-answer/master/ch03/3.3/assets/3.3.5-5-2.gifhttps://raw.github.com/fool2fish/dragon-book-practice-answer/master/ch03/3.3/assets/3.3.5-5-1.gifhttps://raw.github.com/fool2fish/dragon-book-practice-answer/master/ch03/3.3/assets/3.3.5-5.gifhttps://raw.github.com/fool2fish/dragon-book-practice-answer/master/ch03/3.3/assets/3.3.5-4-4.gif
  • 7/22/2019 Dragon Book Exercise Answers Ch03 3.3 3.3

    6/8

    12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub

    https://g ithub.com/fool2fish/drag on-book-exercise-answers/blob/master/ch03/3.3/3.3.md

    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

    https://raw.github.com/fool2fish/dragon-book-practice-answer/master/ch03/3.3/assets/3.3.5-5-4.gifhttps://raw.github.com/fool2fish/dragon-book-practice-answer/master/ch03/3.3/assets/3.3.5-5-3.gif
  • 7/22/2019 Dragon Book Exercise Answers Ch03 3.3 3.3

    7/8

    12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub

    https://g ithub.com/fool2fish/drag on-book-exercise-answers/blob/master/ch03/3.3/3.3.md

    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

  • 7/22/2019 Dragon Book Exercise Answers Ch03 3.3 3.3

    8/8

    12/21/13 dragon-book-exercise-answers/ch03/3.3/3.3.md at master fool2fish/dragon-book-exercise-answers GitHub

    https://g ithub.com/fool2fish/drag on-book-exercise-answers/blob/master/ch03/3.3/3.3.md

    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

    https://github.com/contacthttps://github.com/securityhttps://github.com/site/privacyhttps://github.com/site/termshttps://github.com/abouthttps://github.com/bloghttp://shop.github.com/http://training.github.com/http://developer.github.com/https://status.github.com/