Closed PlusoneWang closed 2 years ago
同學你好:
ss := """"";
一般來說的話 (按照順序讀 token 進來),scanner 的行為應該會如下:
"
,得到第一個 string"
,得到第二個 string (跟第一個 string 合併成一個)"
,接下來 match 到的東西都會被當成 string 的內容;
,當作 string 的內容\n
,因為 string 內不能含有換行符號,所以報錯所以它應該要能偵測到錯誤才對。
若以上回答有回答到同學的問題,請對助教的回覆加上 emoji 👍,助教會幫此 issue 加上「已解決」的標籤,感謝同學的配合。
Hi TA,
Thanks for your reply.
- match 到兩個 ",得到第一個 string
Do you mean that the first two "
will get an empty string?
- match 到兩個 ",得到第二個 string (跟第一個 string 合併成一個)
I don't understand what you mean by 跟第一個 string 合併成一個
.
Do you mean that the first two " will get an empty string?
是的
I don't understand what you mean by 跟第一個 string 合併成一個.
這個在 spec 中有提到: A double quote can be placed within a string constant by writing two consecutive double quotes. For example, an input "aa""bb"
denotes the string constant aa"bb
.
- match 到兩個 ",得到第二個 string (跟第一個 string 合併成一個)`
這個部分改成先把連續兩個 "
變成一個,然後接下來 match 到的都當成 string 的內容會比較好,做起來會比較流暢。
Hi @LittleLaGi,
Thank you for the reply, I'll take more think about the parsing of consecutive double quotes.
As the major question "error detection" has been explicitly answered by 5. match 到 \n,因為 string 內不能含有換行符號,所以報錯
. I think this issue can be closed and marked as solved
.
Hi TAs,
I went through all the test cases provided in hw1 and there are no test cases that contain strings that missing final double quotes. For example, for the following input:
From what I understand, the output of our scanner might be:
or:
It seems like that the scanner of hw1 is unable to detect the wrong string format, am I right?