Understanding of grammar and language

1. understood that symbol string and set operations.

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

D={0,1, … ,9}

Description meaning under represented:

  LUD represents a collection of all the letters and numbers .

  LD   represents a set of strings of all symbols consisting of a letter followed by a number of compositions .

  L4    represented by the set of all strings of symbols of four letters .

  L *    is represented by all the letters of the symbol string comprising a set of null symbol strings .

  D +   represents a set of strings all symbols beginning with the letter, followed by letters, digits .

  L (LUD) *  represents all the symbols of one or several sets of strings of digits .

 

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

  Z->aZb

  Z->ab

  Z->aZb->aaZbb->aaaZbbb->aaaaZbbbb->a...Zb...->a...b...

  A n a number followed by the n b set of all strings of symbols.

 

 

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

  Set I is the identifier, L letter, D is a number to give the title intended by

  VN={I,L,D}    VT={a,b,c,...,x,y,z,0,1,...,9}

  P={    <I>-><L>

      <I>-><I><L>

      <I>-><I><D>

        <L>->a

        <L>->b

        ...

       <L>->z

       <D>->0

       <D>->1

        ...

       <D>->9   }

  S=<I>

 

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.

( 1 ) leftmost derivation :

   E => E+T => T+T => T*F+T => F*F+T => i*F+T => i*i+T => i*i+F => i*i+i

   Rightmost derivation :

   E => E + T => E+F => E+i => T+i => T*F+i => T*i+i => F*i+i => i*i+i

( 2 ) the leftmost derivation :

   E => E+T => T+T => F+T => i+T => i+T*F => i+F*F => i+i*F => i+i*i

   Rightmost derivation :

   E => E + T => E+T*F => E+T*i => E+F*i => E+i*i => T+i*i => F+i*i => i+i*i

( 3 ) leftmost derivation :

   E=> E+T => T+T => F+T => i+T => i+F => i+(E) => i+(E+T) => i+(T+T) => i+(F+T) => i+(i+T) => i+(i+F) => i+(i+i)  

   Rightmost derivation :

   E => E+T => E+F => E+(E) => E+(E+T) => E+(E+F) => E+(E+i) => 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/MRJ1/p/11515319.html