1.已知文法:
S->a|^|(T)
T->T,S|S
分析句型(T,(^,a)),求全部的短语、直接短语和句柄。
解:由题得:S->(T)->(T,S)->(T,(T))->(T,(T,S))->(T,(S,S))->(T,(^,S))->(T,(^,a))
2.构造上下文无关文法,描述语言:
{anbn|n>=0}
{ambn|m>=n>=0}
{(ab)n|n>=0}
{ambn|m,n>=1}
答: (1)S->aSb|ab
(2)S->aaSb|aab
(3)S->(S)|(ab)
(4)S->aSb|ab
3.如果if语句的方法:
stmt->if expr then stmt
| if expr then stmt else stmt
| other
句子if E1 then if E2 then S1 else S2是否有两棵不同的语法树?说明了什么?
答: