1.已知文法:
S->a|^|(T)
T->T,S|S
分析句型(T,(^,a)),求全部的短语、直接短语和句柄。
该句型的语法树为:
可得:短语:^ a ^,a (^,a) T,(^,a) (T,(^,a))
直接短语:^ a
句柄:^
2.构造上下文无关文法,描述语言:
①{anbn|n>=0} :
S => aSb | ab | ε
②{ambn|m>=n>=0}:
S => aSb | a | ab | ε
③ {(ab)n|n>=0} :
S => abS | ε
④ {ambn|m,n>=1}:
S => aSb | ab | Sb | aS
3.条件语句
stmt if expr then stmt
| if expr then stmt else stmt
|other
分析句子if E1 then if E2 then S1 else S2