Lazarus

Free Pascal => General => Topic started by: 440bx on October 01, 2022, 08:08:39 am

Title: likely bug in variable definitions
Post by: 440bx on October 01, 2022, 08:08:39 am
Hello,

Consider the following program:
Code: Pascal  [Select][+][-]
  1. program DefinitionBug;
  2.  
  3. function A() : integer;
  4. var
  5.   Avar : qword - 0;  { is this supposed to compile ??? }
  6.  
  7. begin
  8.   result := Avar + 1;
  9. end;
  10.  
  11. begin
  12.   A();
  13. end.            

the definition in line 5 doesn't make sense but the compiler accepts it.

Comments and/or confirmation that it is a bug, welcome.
Title: Re: likely bug in variable definitions
Post by: Bogen85 on October 01, 2022, 08:35:15 am
That is strange. (that FPC accepts that...)

However JCF (Jedit Code Formatter) can't parse that...

Code: Text  [Select][+][-]
  1. ./lazforum/60776/DefinitionBug.pas(5,20) Error Exception TEParseError  Unexpected token, expected ";"
  2. Near -

And in my editor Line 5 Column 20 is the "-" in "qword - 0"

Can you file a bug report on this against FPC?
Title: Re: likely bug in variable definitions
Post by: ASerge on October 01, 2022, 09:07:50 am
 :D
Code: Pascal  [Select][+][-]
  1. {$LONGSTRINGS OFF}
  2.  
  3. function Test: Integer;
  4. var
  5.   AVar: QWord - 0; { is this supposed to compile ??? }
  6. begin
  7.   Result := High(Char + 'This is also still supported'); // =255
  8. end;
  9.  
  10. begin
  11.   Test;
  12. end.
Title: Re: likely bug in variable definitions
Post by: Bart on October 01, 2022, 01:46:22 pm
The latter one is already reported and I seem to remember it has been fixed in fpc main. Not sure though.

Bart
Title: Re: likely bug in variable definitions
Post by: bytebites on October 01, 2022, 01:58:30 pm
 High(Char + 'This is also still supported')  ->  Error: type identifier not allowed here
Title: Re: likely bug in variable definitions
Post by: Bart on October 01, 2022, 02:25:43 pm
fpc main of today compiles both examples (32/64-bit on windows).
It'll emit an error on the second example in {$H+} mode, not in {$R-} mode.

Bart
Title: Re: likely bug in variable definitions
Post by: Kays on October 01, 2022, 02:46:50 pm
The compiler eliminates arithmetically neutral operations (+0, -0, *1 and div 1). This elimination takes place at an unusual place, though. It’s weird that the issue only arises with qWord and int64.

The latter one is already reported and I seem to remember it has been fixed in fpc main.
I did complain about it once, see #37547 (https://gitlab.com/freepascal.org/fpc/source/-/issues/37547). It was marked as a duplicate of #32994 (https://gitlab.com/freepascal.org/fpc/source/-/issues/32994) which is still open.
Title: Re: likely bug in variable definitions
Post by: Bogen85 on October 01, 2022, 04:11:28 pm

Still compiles and runs for me, I just now updated my git checkout of fpc and rebuilt and reinstalled...
3.3.1-11945-g0a9e1ede72

Code: Pascal  [Select][+][-]
  1. program hellofpcworld;
  2.  
  3. {$LONGSTRINGS OFF}
  4.  
  5. function Test: Integer;
  6. var
  7.   AVar: QWord - 0; { is this supposed to compile ??? }
  8. begin
  9.   AVar := 0;
  10.   writeln('Avar = ', AVar);
  11.   Result := High(Char + 'This is also still supported'); // =255
  12. end;
  13.  
  14. const boo = 'dogÜ';
  15.  
  16. begin
  17.   writeln ('Hello FPC world! ', boo);
  18.   writeln (Test);
  19. end.
  20.  

compiles...

Code: Text  [Select][+][-]
  1. Hint: Start of reading config file /home/shared-development/fpc_usr/lib/fpc/etc/fpc.cfg
  2. Hint: End of reading config file /home/shared-development/fpc_usr/lib/fpc/etc/fpc.cfg
  3. Free Pascal Compiler version 3.3.1 [2022/10/01] for x86_64
  4. Copyright (c) 1993-2022 by Florian Klaempfl and others
  5. Target OS: Linux for x86-64
  6. Compiling lazforum/hellofpcworld.pas
  7. Linking /home/shared-development/sandbox/bin/hellofpcworld
  8. 19 lines compiled, 0.1 sec, 156832 bytes code, 1139896 bytes data
  9. 2 hint(s) issued
  10.  

runs...

Code: Text  [Select][+][-]
  1. Hello FPC world! dogÜ
  2. Avar = 0
  3. 255
  4.  
Title: Re: likely bug in variable definitions
Post by: Arioch on October 01, 2022, 04:39:38 pm
function A() : integer;
var
  Avar : qword - 0;  { is this supposed to compile ??? }

it also works as a global variable

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. var a: qword + 0;
  4.  

however a different type won't work

Code: Pascal  [Select][+][-]
  1. var a: word + 0; // project1.lpr(4,16) Error: Error in type definition
  2. var a: dword + 0; // project1.lpr(4,16) Error: Error in type definition
  3.  

same with int64/int32 types

My guess is this is because CPU register size. I am compiling in Win64, so int64/qword is okay

I can not test Win32 compilation - the Win64 Lazarus installation does not permit it...

Code: Pascal  [Select][+][-]
  1. var a: string + ''; // project1.lpr(4,15) Fatal: Syntax error, ";" expected but "+" found
fails also

so it is not just about "eliminating all the obvious no-ops", something more complex



Title: Re: likely bug in variable definitions
Post by: alpine on October 01, 2022, 05:14:15 pm
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. var
  3.   a: qword + 0;
  4.   b: dword + 0;
  5. begin
  6. end.

Compiles without error. Win32 target.

Lazarus 2.2.2 (rev lazarus_2_2_2) FPC 3.2.2 i386-win32-win32/win64
Title: Re: likely bug in variable definitions
Post by: Arioch on October 01, 2022, 05:18:22 pm
and then what about 16-bit "word + 0"  or "int16 + 0" or "smallint + 0"?
Title: Re: likely bug in variable definitions
Post by: alpine on October 01, 2022, 05:35:11 pm
and then what about 16-bit "word + 0"  or "int16 + 0" or "smallint + 0"?
Code: Pascal  [Select][+][-]
  1. var a: word + 0;
Gives an error.
Title: Re: likely bug in variable definitions
Post by: Arioch on October 01, 2022, 05:40:28 pm
Q.E.D.

at least Intel back-end has thios error triggered on integer types sized in CPU general purpose register sizes ( 1x, 2x, ....)

i think you can make a 6-bytes integer type, subrange, to try intermediate point, but... whatever :-D It is not really needed, just if you think it being funny

something like

Code: Pascal  [Select][+][-]
  1. program;
  2. type  a = 0 .. $ffFFffFFffFF;
  3. var b: a + 0;
  4. begin end.
  5.  

But perhaps here SizeOf(a) and SizeOf(b) would be 8 not 6 ?  At least that is so on Win64 target
Title: Re: likely bug in variable definitions
Post by: alpine on October 01, 2022, 06:00:37 pm
Q.E.D.
My guess is this is because CPU register size. I am compiling in Win64, so int64/qword is okay
And how that relates to the FPC parser? Because (AFAIK) it is an incorrect syntax at the first place.
Title: Re: likely bug in variable definitions
Post by: Arioch on October 01, 2022, 06:05:33 pm
i can only suspect, as vaguely as can be, that memory sizes shorter than GPR trigger a different code path, which includes typecasting, upsizing up to the GRP size multiple

but i don';t know of course, i just observe the black box
Title: Re: likely bug in variable definitions
Post by: alpine on October 01, 2022, 06:38:34 pm
Code: Pascal  [Select][+][-]
  1. var
  2.   a: 1 * dword; // ok
  3.   b: 1 * 0 + dword; // ok
  4.   c: 1 * 1 * 0 + dword; // ok
  5.   d: 1 * 1 * ( 1 - 1 ) + dword; // ok
  6.   e: 1 * 1 * ( 16 - 2 * 8 ) + dword; // ok
  7.   f: dword + #0; // Operator is not overloaded: "LongWord" + "Char"
  8. begin
  9.   writeln(a,b,c,d,e,f);
  10. end.

It seems that an expression non-terminal can follow the : into the variable decl. despite the syntax diagrams
https://www.freepascal.org/docs-html/current/ref/refse22.html

As long it evaluates to zero and includes a suitable type identifier - it is OK  :o
Title: Re: likely bug in variable definitions
Post by: Bogen85 on October 01, 2022, 06:47:31 pm
For me this would not compile, even the ones marked as ok by @y.ivanov

Code: Pascal  [Select][+][-]
  1. program DefinitionBug2;
  2.  
  3. var
  4.   a: 1 * dword;
  5.   b: 1 * 0 + dword;
  6.   c: 1 * 1 * 0 + dword;
  7.   d: 1 * 1 * ( 1 - 1 ) + dword;
  8.   e: 1 * 1 * ( 16 - 2 * 8 ) + dword;
  9.   f: dword + #0;
  10. begin
  11.   writeln(a,b,c,d,e,f);
  12. end.

Code: Text  [Select][+][-]
  1. $ fpc ./lazforum/60776/DefinitionBug2.pas
  2. Free Pascal Compiler version 3.3.1 [2022/10/01] for x86_64
  3. Copyright (c) 1993-2022 by Florian Klaempfl and others
  4. Target OS: Linux for x86-64
  5. Compiling ./lazforum/60776/DefinitionBug2.pas
  6. DefinitionBug2.pas(4,15) Error: Error in type definition
  7. DefinitionBug2.pas(5,19) Error: Error in type definition
  8. DefinitionBug2.pas(6,23) Error: Error in type definition
  9. DefinitionBug2.pas(7,31) Error: Error in type definition
  10. DefinitionBug2.pas(8,36) Error: Error in type definition
  11. DefinitionBug2.pas(9,12) Error: Operator is not overloaded: "LongWord" + "Char"
  12. DefinitionBug2.pas(9,16) Error: Error in type definition
  13. DefinitionBug2.pas(11,12) Error: Can't read or write variables of this type
  14. DefinitionBug2.pas(13) Fatal: There were 8 errors compiling module, stopping
  15. Fatal: Compilation aborted
  16. Error: /home/shared-development/fpc_usr/lib/fpc/3.3.1/ppcx64 returned an error exitcode
Title: Re: likely bug in variable definitions
Post by: Arioch on October 01, 2022, 06:48:24 pm
As long it evaluates to zero

hmmm...

not quite...

Code: Pascal  [Select][+][-]
  1.  var a: int64(nil) + qword;  // project1.lpr(3,26) Error: Error in type definition

 >:D

Code: Pascal  [Select][+][-]
  1. var a: qword + ord(0);
this works though

 O:-)

Code: Pascal  [Select][+][-]
  1. var a: qword + qword(nil);
and this too!

 :-*

Code: Pascal  [Select][+][-]
  1. var a: qword(nil) + uint64;
and this

 :-[

but this still doesn't
Code: Pascal  [Select][+][-]
  1. var a: qword(0);

 >:(

дали детям игрушку :-D

FPC win64 of git Fixes_3_2 - probably 3.2.3 or something
Title: Re: likely bug in variable definitions
Post by: alpine on October 01, 2022, 07:29:40 pm
@Bogen85
Mine is FPC 3.2.2

But:
Code: Text  [Select][+][-]
  1. DefinitionBug2.pas(9,12) Error: Operator is not overloaded: "LongWord" + "Char"
still means there is an expression evaluator lurking.

дали детям игрушку :-D
Exactly.

And I very much wonder what an expression has to do where a type non-terminal was expected.  :o
Title: Re: likely bug in variable definitions
Post by: Arioch on October 01, 2022, 07:57:12 pm
And I very much wonder what an expression has to do where a type non-terminal was expected.  :o

if you really do it "very much" - there are soruces.

I do not, though. Not THAT much.

Guess that is rooted somehow in the need to transit "initialized variables" to AST

The token then get some attibutes, like type, value, sizeof/address, mutability (const/var)

Then later some sanity check is applied to make sure different flags and attributes are consistent, like typed const should have non-zero sezeof and address, and untyped one should lack them.

Type expressions and value expressions are intertwined anyway (because of array <set expression> of type) just tend to use different operators (^ in types, * in values).
Also, why you evaluate value-expressions it might include type-casts, especially implicit ones (that very 1 / 2 == 0 in C but = 0.5 in Pascal )
So, perhaps, unified parser emitting both evaluation tree and adjusted data type was a reasonable implementation.

Having both type ident = type-expr and var ident : type-expr FPC had to run that dual-evaluator after both colon and quality.
As initialized vars were introduced - the parser had to be permitted to create both type and value in var context.
And that is how it ended.

Just speculating.

Also, i remember colon is also used in some more places of the language: goto labelsand variant records. I wonder if the latter have some pinnatas too :-)
Title: Re: likely bug in variable definitions
Post by: alpine on October 01, 2022, 10:15:17 pm
And I very much wonder what an expression has to do where a type non-terminal was expected.  :o

if you really do it "very much" - there are soruces.

I do not, though. Not THAT much.
I won't dig in the compiler sources. At least not for that. 

Known is that the Pascal is (at least was) a LL(1) grammar, the compiler implements a recursive descent parser and that is the foundation of its lightning speed. BTW it is still advertised as such (FPC).

It seems that has changed, IMO the RDP is not capable of such a flippant behavior. This is a direct violation of the syntax as it was defined.

Title: Re: likely bug in variable definitions
Post by: PascalDragon on October 03, 2022, 02:42:04 pm
Known is that the Pascal is (at least was) a LL(1) grammar, the compiler implements a recursive descent parser and that is the foundation of its lightning speed. BTW it is still advertised as such (FPC).

It seems that has changed, IMO the RDP is not capable of such a flippant behavior. This is a direct violation of the syntax as it was defined.

FPC's parser is not derived from a grammar, but it's a hand written one. In this case the “problem” is that the type expression for e.g. a variable or a field is done using the same function that parses a normal expression just set to a different mode (namely “parse type” instead of “parse normal body”) - this is done because the two share quite some functionality - , but for some reason it doesn't correctly filter out expressions that shouldn't be part of a type expression.
Title: Re: likely bug in variable definitions
Post by: alpine on October 03, 2022, 05:23:06 pm
Known is that the Pascal is (at least was) a LL(1) grammar, the compiler implements a recursive descent parser and that is the foundation of its lightning speed. BTW it is still advertised as such (FPC).

It seems that has changed, IMO the RDP is not capable of such a flippant behavior. This is a direct violation of the syntax as it was defined.

FPC's parser is not derived from a grammar, but it's a hand written one.
I wouldn't agree with that. Every formal language have a formal grammar. Syntax diagrams (https://www.freepascal.org/docs-html/ref/refli5.html) are just other representation of the metalanguage such as BNF. So the parser should be implemented strictly according to (deriving from) that grammar, even it was hand written.

In this case the “problem” is that the type expression for e.g. a variable or a field is done using the same function that parses a normal expression just set to a different mode (namely “parse type” instead of “parse normal body”) - this is done because the two share quite some functionality - , but for some reason it doesn't correctly filter out expressions that shouldn't be part of a type expression.
As you confirm, and also as Arioch speculated, the parser parts for <type> and <expression> somehow intertwined here. And I wonder how one can find enough similarities between the two and put them in one function.

I'm pasting some Pascal BNFs I googled (https://condor.depaul.edu/ichu/csc447/notes/wk2/pascal.html). Of course they're not comprehensive, but are correct as a bedding for FPC, though. How it is possible to merge them?

<expression> BNF:
Code: Text  [Select][+][-]
  1. <expression> ::= <simple expression> | <simple expression> <relational operator> <simple expression>
  2. <relational operator> ::= = | <> | < | <= | >= | > | in
  3. <simple expression> ::= <term> | <sign> <term>| <simple expression> <adding operator> <term>
  4. <adding operator> ::= + | - | or
  5. <term> ::= <factor> | <term> <multiplying operator> <factor>
  6. <multiplying operator> ::= * | / | div | mod | and
  7. <factor> ::= <variable> | <unsigned constant> | ( <expression> ) | <function designator> | <set> | not <factor>
  8. ...

<type> BNF:
Code: Text  [Select][+][-]
  1. <type> ::= <simple type> | <structured type> | <pointer type>
  2. <simple type> ::= <scalar type> | <subrange type> | <type identifier>
  3. <scalar type> ::= (<identifier> {,<identifier>})
  4. <subrange type> ::= <constant> .. <constant>
  5. <type identifier> ::= <identifier>
  6. <structured type> ::= <array type> | <record type> | <set type> | <file type>
  7. <array type> ::= array [<index type>{,<index type>}] of <component type>
  8. <index type> ::= <simple type>
  9. <component type> ::= <type>
  10. <record type> ::= record <field list> end
  11. ...

P.S.
Despite the sub-range was defined in https://www.freepascal.org/docs-html/current/ref/refsu4.html#x26-290003.1.1 as:
Code: Text  [Select][+][-]
  1. <subrange type> ::= <constant> .. <constant>
it is more like:
Code: Text  [Select][+][-]
  1. <subrange type> ::= <constant expression> .. <constant expression>
but that introduces ambiguity with the enumeration type (starts with '(') and the weirdness of:
Code: Pascal  [Select][+][-]
  1. const
  2.   c1 = 1;
  3.   c2 = 2;
  4. type
  5.   t1 = 1 + c2 .. 5; // ok, 3..5
  6.   t2 = c1 + c2 .. 5; // ok, 3..5, see the next line
  7.   t3 = (c1 + c2) .. 5; // Error: Duplicate identifier "c1"
  8.   t4 = 2 * (1 + c2) .. 7; // ok, 6..7, see the next line
  9.   t5 = (1 + c2) * 2 .. 7; // Syntax error, "identifier" expected but "ordinal const" found
  10.   t6 = c1 .. (1 + c2) * 2; // ok, 1..6
  11.   t7 = c1 .. (c1 + c2); // ok, 1..3
Title: Re: likely bug in variable definitions
Post by: MarkMLl on October 03, 2022, 08:58:54 pm
I wouldn't agree with that. Every formal language have a formal grammar. Syntax diagrams (https://www.freepascal.org/docs-html/ref/refli5.html) are just other representation of the metalanguage such as BNF. So the parser should be implemented strictly according to (deriving from) that grammar, even it was hand written.

I believe that what he means is that it doesn't use a metalanguage such as a YACC description.

However that does leave me with a question: accepting for the moment that Pascal is LL(1), my understanding is that Wirth's earliest compilers- which presumably includes the first Pascal implementations- were recursive /ascent/ rather than recursive /descent/. Would any CS guru like to comment on whether the two approaches are provably equivalent?

MarkMLl
Title: Re: likely bug in variable definitions
Post by: PascalDragon on October 04, 2022, 01:55:09 pm
Known is that the Pascal is (at least was) a LL(1) grammar, the compiler implements a recursive descent parser and that is the foundation of its lightning speed. BTW it is still advertised as such (FPC).

It seems that has changed, IMO the RDP is not capable of such a flippant behavior. This is a direct violation of the syntax as it was defined.

FPC's parser is not derived from a grammar, but it's a hand written one.
I wouldn't agree with that. Every formal language have a formal grammar. Syntax diagrams (https://www.freepascal.org/docs-html/ref/refli5.html) are just other representation of the metalanguage such as BNF. So the parser should be implemented strictly according to (deriving from) that grammar, even it was hand written.

There never was a formal grammar we began with. And the syntax diagrams that exist are derived from what the compiler supports (and even then some are faulty, because the one writing the documentation didn't find out everything that the compiler itself understands).

In this case the “problem” is that the type expression for e.g. a variable or a field is done using the same function that parses a normal expression just set to a different mode (namely “parse type” instead of “parse normal body”) - this is done because the two share quite some functionality - , but for some reason it doesn't correctly filter out expressions that shouldn't be part of a type expression.
As you confirm, and also as Arioch speculated, the parser parts for <type> and <expression> somehow intertwined here. And I wonder how one can find enough similarities between the two and put them in one function.

It's due to things like this (as you noticed further down as well):

Code: Pascal  [Select][+][-]
  1. program trange;
  2.  
  3. const
  4.   MyMin = 42;
  5.   MyMax = 128;
  6.  
  7. var
  8.   r: MyMin - 4 .. MyMax * SizeOf(Int16);
  9. begin
  10.   Writeln(Low(r), ' .. ', High(r));
  11. end.

P.S.
Despite the sub-range was defined in https://www.freepascal.org/docs-html/current/ref/refsu4.html#x26-290003.1.1 as:
Code: Text  [Select][+][-]
  1. <subrange type> ::= <constant> .. <constant>
it is more like:
Code: Text  [Select][+][-]
  1. <subrange type> ::= <constant expression> .. <constant expression>
but that introduces ambiguity with the enumeration type (starts with '(') and the weirdness of:
Code: Pascal  [Select][+][-]
  1. const
  2.   c1 = 1;
  3.   c2 = 2;
  4. type
  5.   t1 = 1 + c2 .. 5; // ok, 3..5
  6.   t2 = c1 + c2 .. 5; // ok, 3..5, see the next line
  7.   t3 = (c1 + c2) .. 5; // Error: Duplicate identifier "c1"
  8.   t4 = 2 * (1 + c2) .. 7; // ok, 6..7, see the next line
  9.   t5 = (1 + c2) * 2 .. 7; // Syntax error, "identifier" expected but "ordinal const" found
  10.   t6 = c1 .. (1 + c2) * 2; // ok, 1..6
  11.   t7 = c1 .. (c1 + c2); // ok, 1..3

These should probably be reported then...
Title: Re: likely bug in variable definitions
Post by: MarkMLl on October 04, 2022, 02:53:19 pm
There never was a formal grammar we began with. And the syntax diagrams that exist are derived from what the compiler supports (and even then some are faulty, because the one writing the documentation didn't find out everything that the compiler itself understands).

Speaking as somebody who's done his fair share of technical writing: I sympathise.

Even when working in a company with clear responsibilities, getting comprehensive and intelligible information out of designers and developers- and distilling the edge cases into something that passes as English- can be like wringing blood out of a stone.

MarkMLl
Title: Re: likely bug in variable definitions
Post by: alpine on October 04, 2022, 03:11:20 pm
*snip*
P.S.
Despite the sub-range was defined in https://www.freepascal.org/docs-html/current/ref/refsu4.html#x26-290003.1.1 as:
Code: Text  [Select][+][-]
  1. <subrange type> ::= <constant> .. <constant>
it is more like:
Code: Text  [Select][+][-]
  1. <subrange type> ::= <constant expression> .. <constant expression>
but that introduces ambiguity with the enumeration type (starts with '(') and the weirdness of:
Code: Pascal  [Select][+][-]
  1. const
  2.   c1 = 1;
  3.   c2 = 2;
  4. type
  5.   t1 = 1 + c2 .. 5; // ok, 3..5
  6.   t2 = c1 + c2 .. 5; // ok, 3..5, see the next line
  7.   t3 = (c1 + c2) .. 5; // Error: Duplicate identifier "c1"
  8.   t4 = 2 * (1 + c2) .. 7; // ok, 6..7, see the next line
  9.   t5 = (1 + c2) * 2 .. 7; // Syntax error, "identifier" expected but "ordinal const" found
  10.   t6 = c1 .. (1 + c2) * 2; // ok, 1..6
  11.   t7 = c1 .. (c1 + c2); // ok, 1..3

These should probably be reported then...
Not sure the RDP can handle it without back-tracking ... I have tried this on D7 - it fails in the similar way as FPC. Perhaps we can say they're compatible in the way they fail. ;)
At the other hand gpc can handle it, but it is yacc based, i.e. it is LALR(1) parser.
IMO such an issue is inevitable and the only thing that can be done about it is to correct the documentation, i.e. to put a '(' on a right place into the syntax diagram.
Title: Re: likely bug in variable definitions
Post by: Thaddy on October 04, 2022, 05:26:34 pm
@PascalDragon
There was a formal grammar published by Borland. (D5-D7) in BNR notation and that was not a refactoring or a back-port. It was the real deal. I did some work for Borland att.
It was only partially correct though, but neigh complete. And it served many purposes and still does. Sloppy engineering.
Reference: appendix A of the Delphi language guide for D7.
I am a bit bemused you are not aware of that? ;)


( At that time, though, most proper Elvises had left the building(s))
Title: Re: likely bug in variable definitions
Post by: MarkMLl on October 04, 2022, 05:45:13 pm
@PascalDragon
There was a formal grammar published by Borland. (D5-D7) in BNR notation and that was not a refactoring or a back-port. It was the real deal. I did some work for Borland att.
It was only partially correct though, but neigh complete. And it served many purposes and still does. Sloppy engineering.
Reference: appendix A of the Delphi language guide for D7.
I am a bit bemused you are not aware of that? ;)

But there's a big difference between having a grammar that describes a language, and working from a grammar to build a compiler using e.g. YACC.

You said yourself: "partially correct, nigh complete". You can't build a compiler from that.

MarkMLl
Title: Re: likely bug in variable definitions
Post by: marcov on October 04, 2022, 05:50:04 pm
@PascalDragon
There was a formal grammar published by Borland. (D5-D7) in BNR notation and that was not a refactoring or a back-port. It was the real deal. I did some work for Borland att.
It was only partially correct though, but neigh complete. And it served many purposes and still does. Sloppy engineering.

The grammar in the manual, that was for documentation purposes only, and was very simplistic and buggy. It was not really a language definition.


Title: Re: likely bug in variable definitions
Post by: Thaddy on October 04, 2022, 06:06:48 pm
That grammar was used internally too and not just for documentation.
Title: Re: likely bug in variable definitions
Post by: Thaddy on October 04, 2022, 06:08:47 pm
You can't build a compiler from that.

MarkMLl
Actually you CAN! But only partially conformant to the actual release Delphi compilers.
You can actually build A Pascal compiler from the BNF that resembles D7.

And that BNF grammar was leading. Some stupid ghosts - management, money - dropped that guidance along the way. Much like Agile causes more problems than it solves..... >:D
Dropping functional design... in favor of spaghetti code.
Title: Re: likely bug in variable definitions
Post by: marcov on October 04, 2022, 06:17:35 pm
That grammar was used internally too and not just for documentation.

Folding paper airplanes ?   ;D
Title: Re: likely bug in variable definitions
Post by: alpine on October 04, 2022, 06:24:18 pm
@PascalDragon
There was a formal grammar published by Borland. (D5-D7) in BNR notation and that was not a refactoring or a back-port. It was the real deal. I did some work for Borland att.
It was only partially correct though, but neigh complete. And it served many purposes and still does. Sloppy engineering.
Reference: appendix A of the Delphi language guide for D7.
I am a bit bemused you are not aware of that? ;)


( At that time, though, most proper Elvises had left the building(s))
Unfortunately not a proper BNF. See e.g.
Code: Text  [Select][+][-]
  1. TypedConstant -> (ConstExpr | ArrayConstant | RecordConstant)
  2. ArrayConstant -> '(' TypedConstant ',' ')'
  3. RecordConstant -> '(' RecordFieldConstant ';'... ')'
Is it :
Code: Pascal  [Select][+][-]
  1. (1,) // can't add more after the comma
a proper array constant?
Title: Re: likely bug in variable definitions
Post by: PascalDragon on October 05, 2022, 09:06:58 am
@PascalDragon
There was a formal grammar published by Borland. (D5-D7) in BNR notation and that was not a refactoring or a back-port. It was the real deal. I did some work for Borland att.
It was only partially correct though, but neigh complete. And it served many purposes and still does. Sloppy engineering.
Reference: appendix A of the Delphi language guide for D7.
I am a bit bemused you are not aware of that? ;)

Please read again what I wrote (I know that you like to simply skim posts and only extract those parts that you think are relevant) - emphasis mine:

There never was a formal grammar we began with. And the syntax diagrams that exist are derived from what the compiler supports (and even then some are faulty, because the one writing the documentation didn't find out everything that the compiler itself understands).

Yes, there was the grammar included in the TP manuals, but that does not mean that it was used. (And the syntax diagrams is a reference to our own manuals).
Title: Re: likely bug in variable definitions
Post by: MarkMLl on October 05, 2022, 09:20:16 am
Yes, there was the grammar included in the TP manuals, but that does not mean that it was used. (And the syntax diagrams is a reference to our own manuals).

I'm afraid that I get the impression that somebody is unaware that there is a class of tools including YACC etc. that takes a compiler definition as input and spits out a substantial part of a compiler as output. One quite simply can't use a "partially correct, nigh complete" description for automated compiler generation, in the same way that one can't use any other kind of sourcecode in that state.

MarkMLl
Title: Re: likely bug in variable definitions
Post by: Thaddy on October 05, 2022, 11:58:41 am
What did I skip? Other way around! Yes, there was the grammar included in the TP manuals, but that does not mean that it was used. (And the syntax diagrams is a reference to our own manuals).
Not TP but D5-D7, and that WAS used. I was there, you know that. I may have forgotten that: Borland used almost always internal tools, also for their flavor of BNF.
E.g: Their IDE parser was built with it. Not after it.... You can ask anyone who was at Borland at the time. They will confirm it.

Note: as I said before, I did only "minor" work with the rtl/vcl and analysis.

But it is definitely a case of the programmers left the parser in the dark.
TinyPortal © 2005-2018