1.已知文法:
S->a|^|(T)
T->T,S|S
分析句型(T,(^,a)),求全部的短语、直接短语和句柄。
答: S → (T) → (T,S) → (T,(T)) → (T,(T,S)) → (T,(S,S)) → (T,(^,a))
短语: ^ a ^,a (^,a) T,(^,a) (T,(^,a))
直接短语: ^ a
句柄: ^
2.构造上下文无关文法,描述语言:
{anbn|n>=0}
{ambn|m>=n>=0}
if语句
答:(1)文法:G(T) :T → ab | aTb | ε
if(n = 0)
T → ε
else
T → ab | aTb
(2)文法:T → a | aTb | ε
if( m = n = 0)
T → a | ε
else
T → aTb