提交作業
1.將以下文法消除左遞迴,分析符號串 i*i+i 。
並分別求first集、follow集,和select集
e -> e+t | t
t -> t*f | f
f -> (e) | i
first集
first(te')=
first(+te')=
first(ε)=
first(ft')=
first(*ft')=
first((e))=
first((e)|i)=
follow集
follow(e)=
follow(e')=
follow(t)=
follow(t')=
follow(f)=
select集
select(e->te')=
select(e'->+te')=
select(e'->ε)=
select(t->ft')=
select(t'->*ft')=
select(t'->ε)=
select(f->(e))=
select(f->i)=
分析符號串 i*i+i
2.p101練習7(2)(3)文法改寫,並分別求first集、follow集,和select集
(2) a->aabe|a
b->bb|d
提取左公因子:a->aa' a'->abe|ε
消除左遞迴:b->db' b'->bb'|ε
1、 first集:
first(aa') =
first(abe) =
first(ε) =
first(db') =
first(bb') =
first(ε) =
2、 follow集:
follow(a) =
follow(a') =
follow(b) =
follow(b') =
3、 select集:
select(a->aa') = first(aa') =
select(a'->abe) = first(abe) =
select(a'->ε) = first(ε) = ∪follow(a') =
select(b->db') = first(db') =
select(b'->bb') = first(bb') =
select(b'->ε) = first(ε) = ∪follow(b') =
(3) s->aa|b
a->sb
b->ab
將a->sb代入s->aa|b可得:s->sba|b
消除左遞迴:s->bs' s'->bas'|ε b->ab
2、 first集:
first(sba) =
first(b) =
first(bs') =
first(bas') =
first(ε) =
first(ab) =
2、 follow集:
follow(s) =
follow(s') =
follow(b) =
3、select集:
select(s->sba) = first(sba) =
select(s->b) = first(b) =
select(s->bs') = first(bs') =
select(s'->bas') = first(bas') =
select(s->ε) = first(ε) = ∪follow(s') =
select(b->ab) = first(ab) =
課堂練習:
求以下文法的first集、follow集和select集。
(1)s->ap
a->a |ε
a->ca
a->aa
first集:
first(ap)→
first(a)→
first(ε)→
first(ca)→
first(aa)→
follow集:
follow(s)→
follow(a)→
select集:
select(s→ap)=
select(a→a)=
select(a→ε)=
select(a→ca)=
select(a→aa)=
s->ap
s->bq
a->a
a->ca
b->b
b->db
(2)s->ap
s->bq
a->a
a->ca
b->b
b->db
first集:
first(a)→
first(b)→
first(ca)→
first(db)→
first(bq)→
first(ap)→
follow集:
follow(s)→
follow(a)→
follow(b)→
select集:
select(s->ap)=
select(s->bq)=
select(a->a)=
select(a->ca)=
select(b->b)=
select(b->db)=
十 消除左遞迴
1.將以下文法消除左遞迴,分析符號串 i i i e e t t t t f f f e i 消除左遞迴 e te e te t ft t ft f e i first集 first te first te first first ft first ft first e first i follow...
第十次作業 消除左遞迴
1.將以下文法消除左遞迴,求first集 follow集,並分析符號串 i i i e e t t t t f f f e i 消除左遞迴 e te e te t ft t ft f e i first集 first e first i first first ft first ft first t...
第十次作業 消除左遞迴
1.將以下文法消除左遞迴,求first集 follow集,select集,並分析符號串 i i i e e t t t t f f f e i 消除左遞迴 e te e te t ft t ft f e i first集 first te first te first first ft first ...