注釋

2018-06-16 14:19 更新

注釋可以是單行或多行。多行注釋不能嵌套。


因為單行注釋可以包含除了 LineTerminator 字符之外的任何字符,又因為有一般規(guī)則:一個 token 總是盡可能匹配更長,所以一個單行注釋總是包含從 // 到行終結(jié)符之間的所有字符。然而,在該行末尾的 LineTerminator 不被看成是單行注釋的一部分,它被詞法文法識別成語法文法輸入元素流的一部分。這一點非常重要,因為這意味著是否存在單行注釋都不影響自動分號插入進程(見 7.9)。


像空白一樣,注釋會被語法文法簡單丟棄,除了 MultiLineComment 包含行終結(jié)符字符的情況,這種情況下整個注釋會當作一個 LineTerminator 提供給語法文法解析。


語法:


Comment :: 
MultiLineComment 
SingleLineComment


MultiLineComment ::
 /* MultiLineCommentCharsopt*/


MultiLineCommentChars :: 
MultiLineNotAsteriskChar MultiLineCommentCharsopt 
* PostAsteriskCommentCharsopt


PostAsteriskCommentChars :: 
MultiLineNotForwardSlashOrAsteriskChar MultiLineCommentCharsopt 
* PostAsteriskCommentCharsopt


MultiLineNotAsteriskChar :: 
SourceCharacter but not asterisk *


MultiLineNotForwardSlashOrAsteriskChar :: 
SourceCharacter but not forward-slash / or asterisk *


SingleLineComment :: 
// SingleLineCommentCharsopt


SingleLineCommentChars :: 
SingleLineCommentChar SingleLineCommentCharsopt


SingleLineCommentChar :: 
SourceCharacter but not LineTerminator


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號