Principles of Programming work two

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

2. Write the grammar identifier quad materials in the form of 2.2 on page 22 cases.

3. Write the following expressions leftmost derivation and rightmost derivation syntax tree.

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, as well as the similarities and differences of the syntax tree.

Reply:

(1) grammar G (Z): Z-> aZb | ab obtained by deriving:

  G(Z):{a^n*b^|n>1}

(2) grammar G = (Vn, Vt, P, S)

  Where, Vn = {L, M, N}, Vt = {a, b, c, ... x, y, z, 0,1,2, ..., 9}, which is an identifier L, M letters, N is a number.

    P={<L>-><M>

      <L>-><L><M>

      <L>-><L><N>

      <L>->a

      <L>->b

      <L>->c

      .... 

      <L>->z

      <N>-><0>

      ...

      <N>-><9>

      }

    S=<L>

(3)

Guess you like

Origin www.cnblogs.com/zzkai/p/11504083.html