Compile principle of the three

1. Known grammar:

S->a|^|(T)

T->T,S|S

Analysis sentence (T, (^, a)), find all phrases, phrases and directly handle

A:
left the sentence is derived: S
-> (T)
-> (T, S)
-> (T, (T))
-> (T, (T, S))
-> (T, (S , S))
-> (T, (^, S))
-> (T, (^, A))
The grammar derivation tree obtained as follows:

Grammar tree may be obtained:
The phrase:
^ ^, A (^, A) T, (^, A) (T, (^, A))
is directly the phrase:
T, () ^, A
Handle:
T

2. The context-free grammar structure description language:

{a^nb^n|n>=0}

{a^mb^n|m>=n>=0}

The if statement

A:
G [S]: -S-> XSY | XY | [epsilon]
G [S]: -S-> XSYS | X | Y | [epsilon]
IF statement -> if (condition) the then (statements) | IF (condition) the then (Statement 1) else (statement 2)

 

Guess you like

Origin www.cnblogs.com/huangwenshuo/p/11546421.html