逗号分隔类型声明致命错误“=”预期但“,”发现自由帕斯卡
我正在使用 Free Pascal 和 VS Code 学习 Pascal。简单类型声明会发生编译错误。我看过教程和书籍,语法似乎不错。如果我删除“天”,使其成为一个单一的声明,它就可以正常工作。我缺少什么?提前致谢。
program Test;
uses crt;
type
days, age = integer; {Fatal: Syntax error, "=" expected but "," found}
var
myAge: age;
begin
myAge := 5;
writeln(myAge);
end.
I am learning Pascal using Free Pascal and VS Code. A compilation error occurs from a simple type declaration. I have looked at tutorials and books and the syntax seems good. If I remove "days," making it a single declaration it works fine. What am I missing? Thanks in advance.
program Test;
uses crt;
type
days, age = integer; {Fatal: Syntax error, "=" expected but "," found}
var
myAge: age;
begin
myAge := 5;
writeln(myAge);
end.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的语法错误,请参阅 开头的语法图Free Pascal 语言参考,第 3 章类型:
和 第 3.8 章类型别名:
如您所见,Free Pascal 的语法
Type
块中的类型别名为:=
(等号),后跟类型
(可选,声明新类型而不是别名);
(分号)因此,正确的表达你想要的东西的方式是这样的:
嗯,正如您从您所使用的语言的文档中看到的那样,事实并非如此。
您可能没有查看 文档 免费 Pascal 但其他一些语言。
Your syntax is wrong, see the syntax diagram at the beginning of the Free Pascal Language Reference, Chapter 3 Types:
and Chapter 3.8 Type aliases:
As you can see, the syntax for a Free Pascal type alias in a
Type
block is:=
(equals sign) followed bytype
(optional, to declare a new type instead of an alias);
(semicolon)So, the correct way to express what you want would be something like this:
Well, as you can see from the documentation of the language you are writing in, it isn't.
You probably did not look at the documentation of Free Pascal but some other language.