Reputation: 83
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.
Upvotes: 0
Views: 163
Reputation: 369458
Your syntax is wrong, see the syntax diagram at the beginning of the Free Pascal Language Reference, Chapter 3 Types:
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:
program Test;
uses crt;
type
days = integer;
age = integer;
var
myAge: age;
begin
myAge := 5;
writeln(myAge);
end.
I have looked at tutorials and books and the syntax seems good.
Well, as you can see from the documentation of the language you are writing in, it isn't.
What am I missing?
You probably did not look at the documentation of Free Pascal but some other language.
Upvotes: 4