sauv0168
sauv0168

Reputation: 83

Comma Separated Type Declaration Fatal Error "=" expected but "," found Free Pascal

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

Answers (1)

Jörg W Mittag
Jörg W Mittag

Reputation: 369458

Your syntax is wrong, see the syntax diagram at the beginning of the Free Pascal Language Reference, Chapter 3 Types:

Syntax Diagram for Free Pascal Type declaration blocks

and Chapter 3.8 Type aliases:

Syntax Diagram for a Free Pascal type alias declaration

As you can see, the syntax for a Free Pascal type alias in a Type block is:

  1. A new identifier followed by
  2. = (equals sign) followed by
  3. the keyword type (optional, to declare a new type instead of an alias)
  4. the identifier of an existing type followed by
  5. ; (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

Related Questions