Second jobs - language and grammar

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

Z→aZb

Z→aZb→aaZbb

Z→aZb→aaZbb→aaaZbbb

With AZB → → → aaZbb and aaaZbbb → ... Z ... → b and b .... .... ab → a n b n (n≥1)

Grammar G (Z) is defined by A n- B n- set

2. Write grammar quaternion form materials 22 pages identifiers in example 2.2.

G(VN,VT,P,S)

V N = A {(identifier), B (letters), C (number)};

VT={a,b,c,...x,y,z,0,1,...9};

P={  <A>⇒<B>

  <A>⇒<A><B>

<A>⇒<A><C>

 

  <B>⇒a

<B>⇒b

…..

  <B>⇒z

 

  <C>⇒0

<C>⇒1

….

  <C>⇒9

}

S→<C>

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

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.

 

 

 

 

Guess you like

Origin www.cnblogs.com/a1120139442/p/11511390.html