……
我该说啥好呢,不懂 pascal 的是你
http://www.freepascal.org/docs-html/ref/refsu46.html#x138-14800013.2.1
http://www.freepascal.org/docs-html/ref/refsu48.html#x140-15000013.2.3
http://www.dragonkiller.nl/Delphi/delphi2009.html#StatementList
pascal 里一条语句本身是不需包括“;”的,只有 compound statements 这种结构的才需要 ; 来分隔每一条语句。
CompoundStatement : "begin" StatementList "end"
;
StatementList : Statement
| StatementList ";" Statement
;
Statement : Label ":" StatementPart
| StatementPart
| /* empty */
;
Label : tkNumber
| tkIdent
;
StatementPart : CompoundStatement
| IfStatement
| ForStatement
| RepeatStatement
| GotoStatement
| AssignStatement
;
IfStatement : "if" Expression "then" Statement
| "if" Expression "then" Statement "else" Statement
;
GotoStatement : "goto" , Label
| "exit" , [ "(" , Expression , ")" ]
| "break"
| "continue"
;
begin
if b then
a := 1
else
a := 0
end
按照你的说法,上面这条 if 语句是没有结束的
再看 C 的(标准文档6.8 statements and blocks):
statement:
labeled-statement
compound-statement
expression-statement
selection-statement
iteration-statement
jump-statement
compound-statement:
{ block-item-listopt}
block-item-list:
block-item
block-item-list block-item
block-item:
declaration
statement
selection-statement:
if ( expression ) statement
if ( expression ) statement else statement
jump-statement:
goto identifier ;
continue ;
break ;
return expressionopt;
compound-statement 根本就没有用“;”来分看每句。再看 delphi 里 goto 和 C 里 jump 的区别,delphi 里不包括“;”,C 里面都有明确的“;”。很明显,“;”是 C 语言每条语句的组成的一部分,而 pascal 中只是用来作为语句间的分隔
【 在 FlyingBoy (revising hgext.inotify) 的大作中提到: 】
: 完全不对
: pascal里面;表示语句结束,所以else前面有分号是错的