简体   繁体   English

这是Delphi Xe8编译器错误吗?

[英]Is this a Delphi Xe8 compiler error?

The following statements compiles correctly: 以下语句可以正确编译:

procedure test ;
var    xx : string;
begin
   xx := 'a' + '}' + 'b';
end;

if you try to comment with a block comment , the compiler erroneously consider the right parenthesis in the text as the end of the comment. 如果尝试使用块注释进行注释,则编译器会错误地将文本中正确的括号视为注释的结尾。

procedure test ;
var    xx : string;
begin
  {   xx := 'a' + '}' + 'b';  }
end;

Am I missing something ? 我想念什么吗?

When you open a comment then the parser simply ignores the text that follows until it finds the appropriate comment termination. 当您打开注释时,解析器仅忽略后面的文本,直到找到合适的注释终止为止。

  • In the case of // the termination is the end of the line. //的情况下,终止是该行的结尾。
  • In the case of (* the termination is the next instance of *) . (*的情况下,终止是(*的下一个实例*)
  • In the case of { the termination is the next instance of } . {的情况下,终止是}的下一个实例。

Since the compiler does not parse commented out text, it happens upon your } that is inside a string and determinates that the comment has terminated. 由于编译器不会解析注释掉的文本,因此它发生在字符串内的} ,并确定注释已终止。

You state: 您声明:

The compiler erroneously consider the right parenthesis in the text as the end of the comment. 编译器错误地将文本中正确的括号视为注释的结尾。

The mis-think in this statement can be seen in the text that I emphasised. 在我强调的案文中可以看出这种说法的误解。 Once a comment has started, the parser doesn't care about syntax, about quotes, or indeed anything. 注释开始后,解析器将不再关心语法,引号或其他任何内容。 All it does is to read the source until it finds the comment termination. 它所做的只是读取源代码,直到找到注释终止。 It pays no heed to the context in which that comment terminator exists. 它不理会该注释终止符所在的上下文。

Hence this is not a compiler error. 因此,这不是编译器错误。 The compiler is behaving correctly, as designed. 编译器的行为符合设计要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM