Compiler theory 9.11 second job

1. understood that symbol string and set operations.

L={A,B, … ,Z,a,b, … ,z}

D={0,1, … ,9}

Description meaning under represented:

LUD: All letters and numbers in the set

The LD : the set of all strings of symbols consisting of a letter followed by a number composed of

L4 : a 4 All-letter symbols set of strings

* L : the set of all strings of symbols of the alphabet

+ D : All of a symbol string or a set of a plurality of digits

L (LUD) * set of all strings beginning with the letter symbols, followed by the letter, digits

 

 

 

  1. Grammar G (Z): Z-> aZb | ab definition of what kind of language?

answer:

Because Z-> aZb

So Z-> aaZbb

Because Z-> ab

So Z-> aabb

And because Z-> aZb

So aaZbb-> aaabbb

And because Z-> ab

So aabb-> aaabbb

 L ( G ) = {anbn Shu n> = 1} 

Thus defining L ( G ) is defined by A n- B n-

3. Write grammar quaternion form materials 22 pages in Example 2.2 identifier (VN, NT, P, S).

There grammar G = (Vn of, V T , P, S)

  Vn = {L ( identifier ) , D ( letters ) , H ( number )} , V T  = {A, B, C, D, ~~~, Y, Z, 0,1,2, ~~~, 9}   

  P={

         <L>-><D>

    <L>-><L><D>

    <L>-><L><H>

    <D>->a

    <D>->b

    <D>->c

     ……

    <D>->z

    <H>->1

    <H>->2

    <H>->3

     ……

    <H>->9   

  }

  S=<L>

 

4. Write the following expressions leftmost derivation, rightmost derivation.

G (E):

E=> E + T | T

T=>T * F | F

F=>(E)| i

  • i*i+i
  • i+i*i
  • i+(i+i)

 Observe different leftmost and rightmost derivation process.

最左推导:
  E -> E + T
      -> T + T
      -> F + T
      -> i + T
      -> i + T * F
      -> i + F * F
      -> i + i * F
      -> i + i * i
最右推导:
  E -> E + T
     -> E + T * F
     -> E + T * i
     -> E + F * i
     -> E + i * i
     -> T + i * i
     -> F + i * i
     -> i + i * i

Guess you like

Origin www.cnblogs.com/chock/p/11514903.html