程式語言考古題 - 考試

Table of Contents

http://wwwc.moex.gov.tw/ExamQuesFiles/Question/094/035335200.pdf

第四題~寫出字串所有的剖析樹

字串 if a then if b then goto x else if c then goto y else goto z

我簡化一下 if(1) if(2) else(A) if(3) else(B)

我的參考書是2013胡世雄的程式語言 他只畫了兩棵樹

第一組 2搭A和3搭B

第二組 1搭A和3搭B

但我自己可以畫出第三組 1搭B和2搭A

<stm>

<if stm>
(1) (B)
if <bexp> then <stm> else <stm>
| | |
a <if stm> goto z
| | | | | |
if <bexp> then <stm> else <stm>
(2) | | (A) |
b goto x <if stm>
| | | |
if <bexp> then <stm>
| |
c goto y

http://wwwc.moex.gov.tw/ExamQuesFiles/Question/100/100060_34430.pdf

第六題的第一小題 要寫出符合語法且長度不超過3的所有句子

書上給的答案是 a,#a,a!a,a@a 但為什麼##a不行?

因為是一元運算子?但符合語法不是嗎?

感謝解答

--

All Comments

Oscar avatarOscar2015-03-01
開始符號是S ##a是用開始符號w來導的吧
Una avatarUna2015-03-03
S->T,T>W,W>#W,#W>##W,##W>##a
Rosalind avatarRosalind2015-03-07
這兩題我支持你,只能說別盡信書囉
Audriana avatarAudriana2015-03-11
畫出第三組 1搭B和2搭A?? 怎配出來?第一個不是A?
Donna avatarDonna2015-03-12
BBS上畫這樣是我極限了...請多包涵
Christine avatarChristine2015-03-14
對耶 我倒是沒想到 你是對的