紫龍書部分答案

2021-05-18 15:30:42 字數 2926 閱讀 1820

4.6.5

lr(0) items in initial:

s』 -> s

s -> aaab|bbba

a -> e

b ->e

so , i

: s』 ->·s

s ->

·aaab

s ->

·bbba

a ->

·b ->

·follow(a) = follow(b) =

therefore, when input 『a』 we may get a conflict since follow(a) = follow(b).

this grammar is not slr(1)

first(s) =

first(a) = f irst(b) =

follow(s) =

follow(a) = follow(b)=

the parse table isab

$ss -> aaab

s ->bbba

aa -> e

a -> e

bb -> e

b -> e

there are no conflicts , so the grammar is ll(1).

4.6.6

first(s) =

first(a) =

follow(s) =

follow(a) =

the parse table is :a$

ss – sa

s -> a

aa -> a

there is a conflict , so it is not ll(1). theni:

s』 -> ·s

s -> ·sa

s -> ·a

a -> ·a

i:s』 -> ·s

s -> s·a

a -> ·a

i:s -> a·i

:a -> a·i

:s -> sa

·so the parse table is

state

action

goto a

$sa0

s3121

s3acc42

y2r23y3

r34r1r1

there are no conflicts , so the grammar is slr(1).

4.7.1

(a)lri:

s』 ->

·s , $

s ->

·ss+ , $/a

s ->

·ss* , $/a

s ->

·a , $/a i

:s』 -> s

·, $

s -> s

·s+ , $/a

s -> s

·s* , $/a

s ->

·ss+ , +/*/a

s ->

·ss* , +/*/a

s ->

·a , +/*/a i

:s -> a

·, $/+/*/a i

:s ->s s

·, $/a

s -> ss

·+ , $/a

s -> ss

·* , $/a

s -> s

·s+ , +/*/a

s -> s

·s* , +/*/a

s ->

·ss+ , +/*/a

s ->

·ss* , +/*/a

s ->

·a , +/*/a i

:s -> a

·, +/*/a i

:s -> ss

·+ , +/*/a

s -> ss

·* , +/*/a

s -> s

·s+ , +/*/a

s -> s

·s* , +/*/a

s ->

·ss+ , +/*/a

s ->

·ss* , +/*/a

s ->

·a , +/*/a i

:s -> ss+

·, $/a i

:s -> ss*

·, $/a i

:s -> ss+

·, +/*/a i

:s -> ss*

·, +/*/a

(b)lalri:

s』 ->

·s , $

s ->

·ss+ , $/a

s ->

·ss* , $/a

s ->

·a , $/a i

:s』 -> s

·, $

s -> s

·s+ , $/a

s -> s

·s* , $/a

s ->

·ss+ , +/*/a

s ->

·ss* , +/*/a

s ->

·a , +/*/a i

:s -> a

·, $/+/*/a i

:s -> ss

·+ , $/+/*/a

s -> ss

·* , $/+/*/a

s -> s

·s+ , +/*/a

s -> s

·s* , +/*/a

s ->

·ss+ , +/*/a

s ->

·ss* , +/*/a

s ->

·a , +/*/a i

:s -> ss+

·, $/+/*/a i

:s -> ss*

·, $/+/*/a

紫書 STL初步

檢索 int p lower bound a,a n,x a 因為是返回位置所以要減掉起始位置 vector 不定長陣列 a.size 讀大小,a.resize 改變大小,a.push back 向尾部新增元素,a.pop back 刪除最後乙個元素 empty 測試是否為空 vector是模板類 ...

紫書訓練 7 11

貪心場次 密碼 996996 有點思維 include define il inline define pb push back define fi first define se second define ms data,v memset data,v,sizeof data define sc...

紫書訓練 7 16

差分約束 cdq分治 虛樹 密碼 996996 差分約束的部落格 虛樹部落格 虛樹還沒有學習 差分約數裸題 include include include include include include include include include include include define i...