1.已知文法:
S->a|^|(T)
T->T,S|S
分析句型(T,(^,a)),求全部的短语、直接短语和句柄。
2.构造上下文无关文法,描述语言:
{anbn|n>=0}
{ambn|m>=n>=0}
if语句
S->(T)->(T,S)->(T,(T))->(T,(T,S))->(T,(T,a))->(T,(S,a))->(T,(^,a))
短语 :^,a,(^,a),(T,(^,a)), T,(^,a)
直接短语:T,^,a
句柄:T
{a^n,b^n|n>=0}
:G=({S},{a,b,1},P,S}
S ->aSb|1
G(S):S -> aSb|1
If语句:
If(n=0)
then S ->1
else if (n>0)
then S->aSb
else(n<0)
null
{a^m,b^n|n>=0}
:G=({S},{a,b,1},P,S}
S ->aSb|aS|bS|a|b|1
if语句:
If(m=n=0)
then S->1
else if(m=>n=>0)
then S->aSb|aS|bS|a|b
else(m<=n<=0)
null