Ada 2012 RM - 注释和字符串文字
Ada 2012 RM - Comments and String Literals
我正在浏览 Ada 2012 RM,想看看我的理解是否有漏洞或 RM 是否存在漏洞。假设
put_line ("-- this is a not a comment");
是合法的代码,我怎么能从 RM 中推断出它的合法性,因为第 2.7 节指出 "a comment starts with two adjacent hyphens and extends up to the end of the line.",而第 2.6 节指出“string_literal 是由一系列图形字符组成的(可能 none) 包含在两个之间
用作字符串括号的引号。”这两个部分之间似乎存在紧张关系,2.7 会获胜,但显然并非如此。
为了更清楚地了解这里,您需要查看 RM 中的第 2.2 节。
2.2 (1),其中规定;
The text of each compilation is a sequence of separate lexical elements. Each lexical element is formed from a sequence of characters, and is either a delimiter, an identifier, a reserved word, a numeric_literal, a character_literal, a string_literal, or a comment. The meaning of a program depends only on the particular sequences of lexical elements that form its compilations, excluding comments.
和 2.2 (3/2) 其中指出:
"[In some cases an explicit separator is required to separate adjacent lexical elements.] A separator is any of a separator_space space character, a format_effector format effector, or the end of a line, as follows:
A separator_space space character is a separator except within a comment, a string_literal, or a character_literal.
The character whose code point position is 16#09# (CHARACTER TABULATION) Character tabulation (HT) is a separator except within a comment.
The end of a line is always a separator.
One or more separators are allowed between any two adjacent lexical elements, before the first of each compilation, or after the last."
和
A delimiter is either one of the following special characters:
& ' ( ) * + , – . / : ; < = > |
or one of the following compound delimiters each composed of two adjacent special characters
=> .. ** := /= >= <= << >> <>
Each of the special characters listed for single character delimiters is a single delimiter except if this character is used as a character of a compound delimiter, or as a character of a comment, string_literal, character_literal, or numeric_literal.
所以,一旦你过滤掉程序文本的白色-space并将其分解为一系列词法元素,则字符串文字对应的词法元素以双引号字符开头,并且对应于注释的词汇元素以 --.
开头
这些是明显不同的语法项,彼此不冲突。
这也解释了为什么;
X := A - -1
+ B;
给出的结果不同于;
X := A --1
+ B;
破折号之间的 space 分隔符使第一个减号成为与 -1 不同的词法元素,因此 -1 在第一种情况下是数字文字,而 --1 是注释。
我正在浏览 Ada 2012 RM,想看看我的理解是否有漏洞或 RM 是否存在漏洞。假设
put_line ("-- this is a not a comment");
是合法的代码,我怎么能从 RM 中推断出它的合法性,因为第 2.7 节指出 "a comment starts with two adjacent hyphens and extends up to the end of the line.",而第 2.6 节指出“string_literal 是由一系列图形字符组成的(可能 none) 包含在两个之间 用作字符串括号的引号。”这两个部分之间似乎存在紧张关系,2.7 会获胜,但显然并非如此。
为了更清楚地了解这里,您需要查看 RM 中的第 2.2 节。
2.2 (1),其中规定;
The text of each compilation is a sequence of separate lexical elements. Each lexical element is formed from a sequence of characters, and is either a delimiter, an identifier, a reserved word, a numeric_literal, a character_literal, a string_literal, or a comment. The meaning of a program depends only on the particular sequences of lexical elements that form its compilations, excluding comments.
和 2.2 (3/2) 其中指出:
"[In some cases an explicit separator is required to separate adjacent lexical elements.] A separator is any of a separator_space space character, a format_effector format effector, or the end of a line, as follows:
A separator_space space character is a separator except within a comment, a string_literal, or a character_literal.
The character whose code point position is 16#09# (CHARACTER TABULATION) Character tabulation (HT) is a separator except within a comment.
The end of a line is always a separator.
One or more separators are allowed between any two adjacent lexical elements, before the first of each compilation, or after the last."
和
A delimiter is either one of the following special characters:
& ' ( ) * + , – . / : ; < = > |
or one of the following compound delimiters each composed of two adjacent special characters
=> .. ** := /= >= <= << >> <>
Each of the special characters listed for single character delimiters is a single delimiter except if this character is used as a character of a compound delimiter, or as a character of a comment, string_literal, character_literal, or numeric_literal.
所以,一旦你过滤掉程序文本的白色-space并将其分解为一系列词法元素,则字符串文字对应的词法元素以双引号字符开头,并且对应于注释的词汇元素以 --.
开头这些是明显不同的语法项,彼此不冲突。
这也解释了为什么;
X := A - -1
+ B;
给出的结果不同于;
X := A --1
+ B;
破折号之间的 space 分隔符使第一个减号成为与 -1 不同的词法元素,因此 -1 在第一种情况下是数字文字,而 --1 是注释。