Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2023-12

Labels

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Adriaan van Os

According to Section 13.0 of the FreePascal Language Reference (version 3.2.0)

"A label can be an identifier or an integer digit."

What may be meant is that a label can be an identifier or an integer digit-sequence (and that's what the compiler accepts)

	label := digit-sequence | identifier .

ISO-7185 and ISO-10206 Pascal both define

label = digit-sequence .

UCSD-Pascal defines

label = unsigned-integer ":" .

Turbo Pascal (5.5) defines

label = digit-sequence .

in the range 0..9999

MetroWerks Pascal (unfortunately) defined a label as

label = identifier .

The reason for restricting labels to digit-sequences (excluding identifiers) is a parsing problem:

	a :=3;

can also be read as

a : ......

which is the optional <[ label ":" ]> in the rule for <statement>.

statement = [ label ":" ] [ simple-statement | structured-statement | asm-statement ] .

This can be solved, of course, but misses the elegance of the ISO-7185/ISO-10206/UCSD/Turbo Pascal label definition.

Regards,

Adriaan van Os

Reply by email

Jean SUZINEAU
to Adriaan van Os

Le 17/12/2023 à 17:47, Adriaan van Os via fpc-pascal a écrit :

Turbo Pascal (5.5) defines     label = digit-sequence .

Are you sure ?
I had a doubt and I had a look in some very old source code from 1990 made with tp 5.5, it seems you could have letters in labels.

Excerpt of the code:

PROCEDURE EntCh(var col,lin,lmax:byte;var nbre:boolean;var ch:string);

{entr‚e d'une chaŒne de longueur maxi lmax, si nbre=true, on ne peut entrer}

{que des nombres, signes - et + et point d‚cimal ....                      }

LABEL    e00,e01,e02,e03,e04;
VAR      q,cpos,i,v:byte;
          k           :char;
BEGIN   e00:ch:='';
             q :=0;
             cpos:=col;
             gotoXY(col,lin);
             textbackground(7);textcolor(0);
             for i:=1 to lmax do write('_');
             gotoXY(col,lin);goto e02;
         e01:bip;
         e02:k:=readkey;v:=ord(k);
             if ((q>0) and (v=8)) then

            begin

                  cpos:=cpos-1;q:=q-1;
                  gotoXY(cpos,lin);write('_');
                  ch:=left(ch,length(ch)-1);
                  gotoXY(cpos,lin);
                  goto e02;
             end;
             if ((q=0) and (v=13)) then

            begin

                  ch:=k;goto e04;
             end;
             if (v=13) then goto e04;
             case nbre of
             true : if ((v>47)and (v<58)) or (v=46) then
                    goto e03 else goto e01;
             false: if (v>31) then goto e03 else goto e01;

            end; {case nbre of}

         e03:q:=q+1;if (q>lmax) then goto e01;
             write(k);ch:=ch+k;cpos:=cpos+1;goto e02;
         e04:textbackground(0);textcolor(7);
             gotoXY(col,lin);write(ch);write(space(lmax-length(ch)));

END; {procedure EntCh(...)}

{--------------------------------------------------------------------------}

Reply by email

Adriaan van Os
to Jean SUZINEAU
Jean SUZINEAU wrote 8 lines
Le 17/12/2023 à 17:47, Adriaan van Os via fpc-pascal a écrit : > Turbo Pascal (5.5) defines > > label = digit-sequence . Are you sure ? I had a doubt and I had a look in some very old source code from 1990 made with tp 5.5, it seems you could have letters in labels.

You are right. I have a printed cope of the Turbo Pascal 6.0 Programmer's Guide and it says, confusingly, on page 16

"The digIt sequence for a label must be in the range 0.9999"

and on page 8

"A label is a digit sequence in the range 0.999".

but on page 9

"As an extension to Standard Pascal, Turbo Pascal also allows identifiers to functions as labels.

Regards,

Adriaan van Os

Reply by email