Re: [fpc-pascal] case statement

2023-12-16 Thread Adriaan van Os via fpc-pascal
I find the idea of a "closest containing value" rather weird. For me, programming is strict logic, 
not finding something "closest".


What I wrote here, is nonsense. "Closest containing" is rather a grammatical concept, that I 
misunderstood.


Regards,

Adriaan van Os


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] case statement

2023-12-16 Thread Adriaan van Os via fpc-pascal

Tony Whyman via fpc-pascal wrote:

Prospero Pascal was close to ISO Pascal (although I have lost my 
original copy of ISO Pascal) and I would guess that the above is copied 
from ISO Pascal.


You can find the ISO-7185 document on the internet, just search for 
"iso7185.pdf".

A less known aspect of the ISO-7185 Pascal case-statement is that it is an error if none of the 
case-conditions is met.


6.8 .3.5 Case-statements
The values denoted by the case-constants of the case-constant-lists of the 
case-list-elements of a
case-statement shall be distinct and of the same ordinal-type as the expression 
of the case-index
of the case-statement . On execution of the case-statement the case-index shall 
be evaluated . That
value shall then specify execution of the statement of the case-list-element 
closest-containing the
case-constant denoting that value . One of the case-constants shall be equal to 
the value of the
case-index upon entry to the case-statement ; otherwise, it shall be an error.

I find the idea of a "closest containing value" rather weird. For me, programming is strict logic, 
not finding something "closest".


Anyway, the innocent looking case-statement does have some interesting aspects.


As an aside, I much prefer OTHERWISE to ELSE given that it is much closer to natural language. The IF...THEN..ELSE 
construct probably dates back to Algol 60 and I wonder why it was proposed. In normal English use, "else" is 
not used in this way. It usually follows another word, such as "anyone else", "anything else", 
"or else".

You might say

"If I go to town then I will be out. Otherwise, I will stay at home". I would never replace "otherwise" with 
"else" in such a sentence. "Else" belongs in a statement such "Does anyone else have a view".


Interesting observation !

Regards,

Adriaan van Os

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] case statement

2023-12-16 Thread Tony Whyman via fpc-pascal

On 16/12/2023 19:07, Gerhard Scholz via fpc-pascal wrote:


ELSE/OTHERWISE

I assume that came historically; the first implementation of a PASCAL 
compiler I have seen had no else or otherwise in the case startement. 
Some ater dialects introduced ELSE, other dialect(s) used OTHERWISE, 
FPC then allowed both.


The historical context has interested me as well.

Going back to the original "Pascal User Manual and Report" (Jensen and 
Wirth 1978), there is no Else/Otherwise clause for a case statement. The 
syntax is given as (in the original BNF):


 ::= case  of
   |;] end
 ::=  :  | 
 ::=  | [ ,  ]

Note that the semi-colon is used here in its traditional Algol role as a 
statement separator and not the 'C' usage as a statement terminator.


Back in the early eighties, I worked at ICL and we made extensive use of 
the Prospero Pascal compiler building embedded systems based on the Z80 
microprocessor. I still have a 1988 edition of the language 
specification, and this uses EBNF to define the case statement as:


case-statement = "CASE" case-index "OF"
  case-list-element {";" case-list-element }
   [ ";" OTHERWISE statement][";"] "END"

case-index = expression
case-list-element = case-range-list ":" statement
case-range-list = case-range {"," case-range }
case-range = case-constant [".." case-constant ]
case-constant = constant

What is interesting about the above is not just that it uses "otherwise" 
but that it insists on a semi-colon before the "otherwise". This may not 
have been strictly necessary but it does enforce the separation between 
the case -list-elements and the "otherwise", making the "otherwise" 
clause into another case-list-element. It also aids readability and it 
may be why I have always added a semi-colon after the final 
case-list-element. Note that the final optional ";" is probably needed 
to allow those that always like to end a statement in a semi-colon.


Prospero Pascal was close to ISO Pascal (although I have lost my 
original copy of ISO Pascal) and I would guess that the above is copied 
from ISO Pascal.


The change from "otherwise" to "else" is probably a Borland Pascal 
invention preferring a shorter word and then overlooking the importance 
of the semi-colon case-list-element separator and the resulting 
ambiguity. The same error then flowed through to exception handling.


As an aside, I much prefer OTHERWISE to ELSE given that it is much 
closer to natural language. The IF...THEN..ELSE construct probably dates 
back to Algol 60 and I wonder why it was proposed. In normal English 
use, "else" is not used in this way. It usually follows another word, 
such as "anyone else", "anything else", "or else".


You might say

"If I go to town then I will be out. Otherwise, I will stay at home". I 
would never replace "otherwise" with "else" in such a sentence. "Else" 
belongs in a statement such "Does anyone else have a view".


Tony Whyman


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] case statement

2023-12-16 Thread Gerhard Scholz via fpc-pascal

statement list = statement { ";" statement }

statementlist itself is not explained; I assume "statementlist" to be the 
same as "statement list"


It is included in the definition of the try...except statement.



ELSE/OTHERWISE

I assume that came historically; the first implementation of a PASCAL 
compiler I have seen had no else or otherwise in the case startement. Some 
ater dialects introduced ELSE, other dialect(s) used OTHERWISE, FPC then 
allowed both.




Ambiguity:

It is so. I was a bit astonished.

  i := 4 ;
  case i of
1,
2: if odd ( i )
 then write ( 'odd' )
else write ( 'even' ) ;
   end ;

produces nothing, else is part of the if statement, in case of ambiguity the 
nearest possibility is used.


  i := 4 ;
  case i of
1,
2: if odd ( i )
 then write ( 'odd' )
   ; else write ( 'even' ) ;
   end ;

produces the print 'even', else is part of the case statement

As I read the syntax of the case statement in ref.pdf, the semicolon before 
the else is not even allowed.


the syntax is (see below)

case-statement = "CASE" expression "OF" case { ";" case } [ else-part ] 
[ ";" ] .



if you change that to

case-statement = "CASE" expression "OF" case { ";" case } [ ";" ] [ 
else-part [ ";" ] ] .



then you have what the compiler does.



I never had the problem because before the else I always inserted a ";"

- Original Message - 


From: "Adriaan van Os via fpc-pascal" 
To: "FPC-Pascal users discussions" 
Cc: "Adriaan van Os" 
Sent: Thursday, December 14, 2023 4:53 PM
Subject: [fpc-pascal] case statement




I am looking in detail at the syntax diagrams in the Freepascal Language 
Reference (version 3.2.0)


Section 13.2.2 discusses the case-statement. Translated to EBNF (WSN) the 
syntax is


case-statement = "CASE" expression "OF" case { ";" case } [ else-part ] 
[ ";" ] .
case = constant [ ".." constant ] { "," constant [ ".." constant ] } ":" 
statement .

else-part = [ "ELSE" | "OTHERWISE" ] statementlist .

If this is correct (and the compiler really allows it) then a semicolon 
between  and  is not required. Consequently, there is an 
ambiguity between an if-then-else statement (as last statement of the 
) and an if-then statement (as last statement of the ) and an 
. This is extremely dangerous and I feel that at least the 
Language Reference should warn against it.


Even with an obliged semicolon, I always use "OTHERWISE instead of ELSE, 
but that's my personal preference.


By the way, the Language Reference doesn't specify what a  
is.


Regards,

Adriaan van Os

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal 


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] More syntax questions (part 4)

2023-12-16 Thread Michael Van Canneyt via fpc-pascal




On Sat, 16 Dec 2023, Adriaan van Os via fpc-pascal wrote:



More questions about the FreePascal Language Reference (version 3.2.0), part 
4


34. Are macpas LEAVE and CYCLE statements undocumented ?


Yes.



35. Are macpas ellipsis (...) parameters undocumented ?


Yes.



36. Is the macpas RETURN statement undocumented ?


Yes.



37. Shouldn't the macpas "mwpascal" modifier be added to ?

	call-modifiers = "register" | "cdecl" | "pascal" | "stdcall" | 
"safecall" | "inline" | "mwpascal" .
	call-modifiers = "cdecl" | "inline" | "local" | "nostackframe" | 
"overload" | "pascal" | "register" | "safecall" | "saveregisters" | 
"softfloat" | "stdcall" | "varargs" | "mwpascal".


Yes. There are even more.



38. Is a  rule missing ?

	constref-parameter = "CONSTREF" identifier-list [ ":" [ "ARRAY" "OF" 
] type-identifier ] .


where

	parameter-declaration = value-parameter | variable-parameter | 
out-parameter | constant-parameter | out-parameter  | constref-parameter .


Yes.



39. Section 16.7 defines a rule  and a rule 

library = library-header ";" [ uses-clause ] block "." .
exports-clause = "exports" exports-list ";" .

The exports-clause rule however doesn't seem to be referenced anywhere in the 
syntax, so it may have to be added to the  rule ?


To the library rule, but also to the unit rule, because it can also appear
in a unit...



40. < recordoperator-definition> =  ?


Yes.



41. Is it correct that  is referenced only in the record 
 rule ? I would expect something like an 
 in various declaration rules.


To the best of my knowledge, only records support operator definitions.

The 'operator' chapter handles 'global' operators which are at the level of
global functions/procedures.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] More syntax questions (part 3)

2023-12-16 Thread Michael Van Canneyt via fpc-pascal



On Sat, 16 Dec 2023, Wayne Sherman wrote:


On Sat, Dec 16, 2023 at 7:35 AM Michael Van Canneyt wrote:

Hm. Lot of corrections to do.. I'll be busy tonight :-)


Are these grammars in GIT so others can help by submitting merge
requests?  That way you can spread the love :-)



Everything concerning FPC is in git :-)

https://gitlab.com/freepascal.org/fpc/documentation/-/tree/main/syntax?ref_type=heads

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] More syntax questions (part 3)

2023-12-16 Thread Wayne Sherman via fpc-pascal
On Sat, Dec 16, 2023 at 7:35 AM Michael Van Canneyt wrote:
> Hm. Lot of corrections to do.. I'll be busy tonight :-)

Are these grammars in GIT so others can help by submitting merge
requests?  That way you can spread the love :-)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] More syntax questions (part 3)

2023-12-16 Thread Michael Van Canneyt via fpc-pascal




On Sat, 16 Dec 2023, Adriaan van Os via fpc-pascal wrote:



More questions about the FreePascal Language Reference (version 3.2.0)  part 
3


26. Am I correct to assume the following equivalents for rules that I 
couldn't find a definiton for:


formal-parameter-list  = parameter-declaration .
parameter-list = parameter-declaration .
hint-directives= { hint-directive } .
hint-modifiers = call-modifiers .
hintdirective  = hint-directive .
hintdirectives = hint-directives .
integer   := [ sign ] unsigned-integer .
integer-constant  := integer .
integerconstant   := integer-constant .
typed-declaration  = type-declaration .


Yes, although integer-constant, integerconstant and integer should simply all be
the same. I will correct that.



27. Section 13.2 defines a rule for  refering to a rule 



	structured-statement = compound-statement | conditional-statement | 
repetitive-statement | with-statement | exception-statement .


Am I correct to assume ?

exception-statement = try-except-statement | try-finally-statement .


Yes.



where

	try-except-statement = "try" statement-list "except" 
exceptionhandlers "END" .
	try-finally-statement = "try" statement-list "finally" 
finally-statements "END" .


Yes.



28.  The documentation for macpas "UNIV" is missing ?


I have no idea what this is ?



29. Am I correct to assume ?

ordinal-type = ordinal-type-identifier .
ordinal-type-identifier = identifier .


Yes.



30. Am I correct to assume that  was meant to be 
 ?


Yes.



31. Are the operators "<<" and ">>" missing  in the syntax diagrams ?


Yes and no.

I preferred not to document these since they are in fact C operators which I 
think
are a historical mistake.



32. Are the set operators "include", "exclude" missing in the syntax diagrams 
? Is "><" missing (specifically) as set operator in the syntax diagrams ?


Include/Exclude are not operators. They are procedure calls.

To illustrate, the following fails to compile:
---
type
  TEnum = (one,two,three);
  TEnums = set of TEnum;

var a : TEnums;

begin
  a:=[];
  a:=Include(a,one);
end.
---
iu.pp(9,6) Error: Incompatible types: got "untyped" expected "TEnums"
iu.pp(10,4) Fatal: There were 1 errors compiling module, stopping

The missing >< is an oversight



33. Section 12.1 gives "sign" in boldface in the rule for , 
suggesting that it is a keyword. Is that correct ?


No.

It is not a keyword, but one of '+' or '-'.

Hm. Lot of corrections to do.. I'll be busy tonight :-)

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] More syntax questions (part 2)

2023-12-16 Thread Michael Van Canneyt via fpc-pascal




On Sat, 16 Dec 2023, Adriaan van Os via fpc-pascal wrote:



More questions about the FreePascal Language Reference (version 3.2.0)  part 
2


17. For the following rules, I couldn't find a definition in the Language 
Reference. Can I assume they can all be defined as  ?


object-type-identifier = identifier .
field-identifier   = identifier .
interface-identifier   = identifier .
interface-type-identifier  = identifier .
method-identifier  = identifier .
procedure-identifier   = identifier .
protocol-identifier= identifier .
protocol-type-identifier   = identifier .
qualified-method-identifier= identifier .
result-identifier  = identifier .
type-identifier= identifier .
function-identifier= identifier .
unit-identifier= identifier .
variable-identifier= identifier .


Yes.

The idea was to use these "dedicated names" to convey that the identifier must 
be of a certain type.

You cannot express this concept in a formal syntax, but for a formal syntax the 
above is correct.



18. Section 14.4.1 defines a rule 

	value-parameter = identifier-list ":" [ "ARRAY" "OF" ] parameter-type 
| identifier ":" type-identifier "=" default-parameter-value .


I couldn't find a rule for . If  equals 
 then it may be easier to name it  ?


Not quite. it can also be 'const' (the 'array of const' construct).

This diagram needs to be enhanced, I suppose the following is more correct:

(identifier [ "=" constant-expression ] | "array" "of" ("const" | identifier))



19. Sections 3.6, 14.2 and 15.2 refer to a rule .

function-header = "FUNCTION" formal-parameter-list ":" result-type .
	function-header = "FUNCTION" ( identifier | 
qualified-method-identifier ) formal-parameter-list ":" result-type [ 
modifiers ] [ hintdirectives ] .
	operator-definition = "operator" ( assignment-operator-definition | 
arithmetic-operator-definition | comparision-operator-definition ) 
result-identifier ":" result-type ";" subroutine-block .


I couldn't find a rule for . Can I assume ?

result-type = type-identifier .


Yes.



20. For the following rules, I couldn't find a definition in the Language 
Reference. Can I assume they can all be defined as  ?


guid = single-quoted-string .
string-constant-declaration = single-quoted-string .
string-literal = single-quoted-string .
stringconstant = single-quoted-string .


Yes.



where  is a parser built-in rule that parses two 
consecutive single-quote chars as a literal single-quote char ? and that may 
not contain CR and LF characters  ? or any other control characters ?


Yes. 
Following your remarks, I was planning to introduce a list of "parser built-in"

rules, as I need them to define the constants.



21. Can I assume ?

statement-list = statement { ";" statement } .
statementlist = statement-list .


Yes.



22. Various rules refer to a rule  for which I can't find 
the rule. What is it ?


identifier.



23. Section 12.2 defines a rule  that references rules 
 and .


	function-call = ( function-identifier | method-designator | 
qualified-method-designator | variable-reference ) [ actual-parameter-list ] 
.


I can't find the rules for  and 
. What are they ?


With the appearance of nested classes and type definitions, they are actually 
the same.

method-designator = qualified-method-designator = identifier ({ "." identifier 
})

So the function-call can be simplified to
  function-call = ( method-designator | variable-reference ) [ 
actual-parameter-list ]

maybe introducing a

  fully-qualified-identifier = identifier ({ "." identifier })

and using that everywhere instead is a better approach.



24. Sections 14.4.1 and 14.4.4 define rules that refer to a rule 
.


	value-parameter = identifier-list ":" [ "ARRAY" "OF" ] parameter-type 
| identifier ":" type-identifier "=" default-parameter-value .
	constant-parameter = "CONST" ( identifier-list [ ":" [ "ARRAY" "OF" ] 
type-identifier ] | identifier ":" type-identifier "=" 
default-parameter-value ) .


I can't find the rule for . What is it ?


default-parameter-value = constant-expression



25. Section 16.2 defines a  rule  that refers to a rule 



	interface-part = "INTERFACE"  [ uses-clause ]  { 
constant-declaration-part  | type-declaration-part | 
variable-declaration-part | property-declaration-part | 
procedure-headers-part } .


I can't find the rule . What is it ?



That should be
   property-declaration-part = property definition { ";" property definition }

("property definition" is defined in the class declaration diagram)

Michael.
___
fpc-pascal ma

[fpc-pascal] More syntax questions (part 4)

2023-12-16 Thread Adriaan van Os via fpc-pascal



More questions about the FreePascal Language Reference (version 3.2.0), part 4

34. Are macpas LEAVE and CYCLE statements undocumented ?

35. Are macpas ellipsis (...) parameters undocumented ?

36. Is the macpas RETURN statement undocumented ?

37. Shouldn't the macpas "mwpascal" modifier be added to ?

call-modifiers = "register" | "cdecl" | "pascal" | "stdcall" | "safecall" | 
"inline" | "mwpascal" .
	call-modifiers = "cdecl" | "inline" | "local" | "nostackframe" | "overload" | "pascal" | 
"register" | "safecall" | "saveregisters" | "softfloat" | "stdcall" | "varargs" | "mwpascal".


38. Is a  rule missing ?

constref-parameter = "CONSTREF" identifier-list [ ":" [ "ARRAY" "OF" ] 
type-identifier ] .

where

	parameter-declaration = value-parameter | variable-parameter | out-parameter | constant-parameter 
| out-parameter  | constref-parameter .


39. Section 16.7 defines a rule  and a rule 

library = library-header ";" [ uses-clause ] block "." .
exports-clause = "exports" exports-list ";" .

The exports-clause rule however doesn't seem to be referenced anywhere in the syntax, so it may 
have to be added to the  rule ?


40. < recordoperator-definition> =  ?

41. Is it correct that  is referenced only in the record  rule 
? I would expect something like an  in various declaration rules.


(to be continued)

Adriaan van Os



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] More syntax questions (and more to follow)

2023-12-16 Thread Michael Van Canneyt via fpc-pascal




On Sat, 16 Dec 2023, Adriaan van Os via fpc-pascal wrote:


Michael Van Canneyt via fpc-pascal wrote:

Thanks for the replies.


Please note that the syntax diagrams are NOT meant to be exhaustive.
They are an aid to explain the syntax. I strive to make them as correct as
possible, but they make no pretense to being complete.


Anyway, I strive to make the syntax complete and correct. When it is ready, I 
can send it in to be added as an Appendix to the Language Reference manual. I 
have an ebfn-driven general (back-parsing) parser, that already works for 
Oberon-0 end UCSD-Pascal. So, the ebnf can be tested.


There are several typesetting systems that can convert EBNF to a nice
diagram, so it can be nicely typeset too.

I have long been looking for an EBNF, and only found several syntaxes for other
systems, so that would be really good if you could make one. I would include
it at once :-)

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] More syntax questions (part 3)

2023-12-16 Thread Adriaan van Os via fpc-pascal



More questions about the FreePascal Language Reference (version 3.2.0)  part 3

26. Am I correct to assume the following equivalents for rules that I couldn't 
find a definiton for:

formal-parameter-list  = parameter-declaration .
parameter-list = parameter-declaration .
hint-directives= { hint-directive } .
hint-modifiers = call-modifiers .
hintdirective  = hint-directive .
hintdirectives = hint-directives .
integer   := [ sign ] unsigned-integer .
integer-constant  := integer .
integerconstant   := integer-constant .
typed-declaration  = type-declaration .

27. Section 13.2 defines a rule for  refering to a rule 


	structured-statement = compound-statement | conditional-statement | repetitive-statement | 
with-statement | exception-statement .


Am I correct to assume ?

exception-statement = try-except-statement | try-finally-statement .

where

try-except-statement = "try" statement-list "except" exceptionhandlers 
"END" .
try-finally-statement = "try" statement-list "finally" finally-statements 
"END" .

28.  The documentation for macpas "UNIV" is missing ?

29. Am I correct to assume ?

ordinal-type = ordinal-type-identifier .
ordinal-type-identifier = identifier .

30. Am I correct to assume that  was meant to be 
 ?

31. Are the operators "<<" and ">>" missing  in the syntax diagrams ?

32. Are the set operators "include", "exclude" missing in the syntax diagrams ? Is "><" missing 
(specifically) as set operator in the syntax diagrams ?


33. Section 12.1 gives "sign" in boldface in the rule for , suggesting that it is a 
keyword. Is that correct ?


(to be continued)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] More syntax questions (part 2)

2023-12-16 Thread Adriaan van Os via fpc-pascal



More questions about the FreePascal Language Reference (version 3.2.0)  part 2

17. For the following rules, I couldn't find a definition in the Language Reference. Can I assume 
they can all be defined as  ?


object-type-identifier = identifier .
field-identifier   = identifier .
interface-identifier   = identifier .
interface-type-identifier  = identifier .
method-identifier  = identifier .
procedure-identifier   = identifier .
protocol-identifier= identifier .
protocol-type-identifier   = identifier .
qualified-method-identifier= identifier .
result-identifier  = identifier .
type-identifier= identifier .
function-identifier= identifier .
unit-identifier= identifier .
variable-identifier= identifier .

18. Section 14.4.1 defines a rule 

	value-parameter = identifier-list ":" [ "ARRAY" "OF" ] parameter-type | identifier ":" 
type-identifier "=" default-parameter-value .


I couldn't find a rule for . If  equals  then it 
may be easier to name it  ?


19. Sections 3.6, 14.2 and 15.2 refer to a rule .

function-header = "FUNCTION" formal-parameter-list ":" result-type .
	function-header = "FUNCTION" ( identifier | qualified-method-identifier ) formal-parameter-list 
":" result-type [ modifiers ] [ hintdirectives ] .
	operator-definition = "operator" ( assignment-operator-definition | arithmetic-operator-definition 
| comparision-operator-definition ) result-identifier ":" result-type ";" subroutine-block .


I couldn't find a rule for . Can I assume ?

result-type = type-identifier .

20. For the following rules, I couldn't find a definition in the Language Reference. Can I assume 
they can all be defined as  ?


guid = single-quoted-string .
string-constant-declaration = single-quoted-string .
string-literal = single-quoted-string .
stringconstant = single-quoted-string .

where  is a parser built-in rule that parses two consecutive single-quote 
chars as a literal single-quote char ? and that may not contain CR and LF characters  ? or any 
other control characters ?


21. Can I assume ?

statement-list = statement { ";" statement } .
statementlist = statement-list .

22. Various rules refer to a rule  for which I can't find 
the rule. What is it ?

23. Section 12.2 defines a rule  that references rules  
and .


	function-call = ( function-identifier | method-designator | qualified-method-designator | 
variable-reference ) [ actual-parameter-list ] .


I can't find the rules for  and 
. What are they ?

24. Sections 14.4.1 and 14.4.4 define rules that refer to a rule 
.

	value-parameter = identifier-list ":" [ "ARRAY" "OF" ] parameter-type | identifier ":" 
type-identifier "=" default-parameter-value .
	constant-parameter = "CONST" ( identifier-list [ ":" [ "ARRAY" "OF" ] type-identifier ] | 
identifier ":" type-identifier "=" default-parameter-value ) .


I can't find the rule for . What is it ?

25. Section 16.2 defines a  rule  that refers to a rule 


	interface-part = "INTERFACE"  [ uses-clause ]  { constant-declaration-part  | 
type-declaration-part | variable-declaration-part | property-declaration-part | 
procedure-headers-part } .


I can't find the rule . What is it ?

(more to follow)




___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] More syntax questions (and more to follow)

2023-12-16 Thread Adriaan van Os via fpc-pascal

Michael Van Canneyt via fpc-pascal wrote:

Thanks for the replies.


Please note that the syntax diagrams are NOT meant to be exhaustive.
They are an aid to explain the syntax. I strive to make them as correct as
possible, but they make no pretense to being complete.


Anyway, I strive to make the syntax complete and correct. When it is ready, I can send it in to be 
added as an Appendix to the Language Reference manual. I have an ebfn-driven general (back-parsing) 
parser, that already works for Oberon-0 end UCSD-Pascal. So, the ebnf can be tested.


Regards,

Adriaan van Os

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] More syntax questions (and more to follow)

2023-12-16 Thread Michael Van Canneyt via fpc-pascal




On Sat, 16 Dec 2023, Adriaan van Os via fpc-pascal wrote:



More questions about the FreePascal Language Reference (version 3.2.0)

1. Section 17.1 defines a rule  and 

	raise-statement = "raise" [ exception-instance [ exception-address ] 
] .
	exception-address = "at" exception-address [ "," address-expression ] 
.


a) Is it correct that  defines itself recursively ?


No.

That should be exception-address = "at" address-factor

Corrected.



b) I can't find the rule that defines . What is it ?


Typo, should be address-factor.

Corrected.



c) I can't find the rule that defines . What is it ?


An expression of type exception.

Added.



2. Section 12.1 refers to a rule 

	factor = "(" expression ")" | variable-reference | function-call | 
unsigned-constant| "NOT" factor | "sign" factor | set-constructor | 
value-typecast | address-factor .


I can't find the rule  but it may be the same as the rule 
 given in section 12.7 ?


Yes. Corrected.



	addressfactor = "@" ( variable-reference | procedure-identifier | 
function-identifier | qualified-method-identifier ) .


3. Section 2.2 refers to a rule 

	typed-constant = constant | address-constant | array-constant | 
record-constant | procedural-constant .


I can't find the rule . What is it ?


A constant of type address. So either Nil or @identifier.



4. Section 2.2 also refers to a rule 

	typed-constant = constant | address-constant | array-constant | 
record-constant | procedural-constant .


I can't find the rule . What is it ?


A constant of type array, obviously.

Needs to be added.



5. Section 2.2 also refers to a rule 

	typed-constant = constant | address-constant | array-constant | 
record-constant | procedural-constant .


I can't find the rule . What is it ?


A constant of type record.

Needs to be added.



6. Section 2.2 also refers to a rule 

	typed-constant = constant | address-constant | array-constant | 
record-constant | procedural-constant .


I can't find the rule . What is it ?


Address-factor of procedural type.

Needs to be added.



7. Section 13.3 refers to a rule 

asm-statement = "asm" assembler-code "END" [ registerlist ] .

I can't find a rule for  What is it, from the point of view 
of parsing Pascal ?


Undefined. Skip all tokens till you meet END.




8. Section 10.1 refers to  a rule 

	helper-type = ( "CLASS" | "RECORD" | "TYPE" ) "helper" [ "(" 
basehelper ")" ] "FOR" identifier  { helper-component-list } "END" 
hint-modifiers .


I can't find a rule for . What is it ?


An identifier.

Corrected.




9. Sections 17.2 and 6.1 refer to a rule 

	exception-handler = "ON" [ identifier ":" ] class-type-identifier 
"DO" statement .
	class-heritage = "(" class-type-identifier [ 
class-implemented-interfaces ] ")" .


I can assume ?

class-type-identifier = identifier .


Yes.

Added.



10. Section 11.2 refers to a rule 

	objc-class-heritage = "(" [ objective-Cclass-type-identifier ] [ 
objc-implemented-protocols ] ")" .


I can assume ?

objective-Cclass-type-identifier = identifier .


Yes.

Added.



11. Section 6.1 refers to a rule 

class-reference-type = "CLASS" "OF" classtype .

I can't find a rule for . What is it ?


class-type-identifier (or identifier)

Added.



12. Section 13.2 refers to a rule 

	structured-statement = compound-statement | conditional-statement | 
repetitive-statement | with-statement | exception-statement .


I can't find a rule for . What is it ?


You missed it. It is defined under 'Structured statements'.



13. Section 6.1 referes to a rule 

	component-list = [ visibility-specifier ] { field-definition } { 
const-declaration-part | type-declaration-part | variable-declaration-part | 
class-variable-declaration-part | method-definition | property-definition } .


I can assume ?

const-declaration-part = constant-declaration-part .


Yes. Corrected.



14. Sections 2.2, 3.1.1, 3.3.2, 4.7 and 13.2.2 refer to a rule 

	typed-constant = constant | address-constant | array-constant | 
record-constant | procedural-constant .

subrange-type = constant ".." constant .
variant = constant { "," constant } ":" "(" [ field-list ] ")" .
default-specifier = "default" [ constant ] | "nodefault" .
stored-specifier = "stored" ( constant | identifier ) .
	case = constant [ ".." constant ] { "," constant [ ".." constant ] } 
":" statement .


I can't find a rule for . What is it ?


A simple constant. ordinal, string or float.

Needs to be added.




15. Sections 5.1 and 6.6.1 refer to a rule 

const-definition = "CONST" identifier "=" constant-expression ";" .
	class-method-directives = ( ( "virtual" | "dynamic" ) [ ";" 
"abstract" ] | "reintroduce" ";" | "override" ";" | "message" 
constant-expression ) [ call-modifiers ";" ] .


I can assume ?

constant-expression = expression .


As far as parsing is concerned, yes.




16. Section 12.1 refers to a rule 

	unsigned-constant = unsigned-number | charac

[fpc-pascal] More syntax questions (and more to follow)

2023-12-16 Thread Adriaan van Os via fpc-pascal



More questions about the FreePascal Language Reference (version 3.2.0)

1. Section 17.1 defines a rule  and 

raise-statement = "raise" [ exception-instance [ exception-address ] ] .
exception-address = "at" exception-address [ "," address-expression ] .

a) Is it correct that  defines itself recursively ?

b) I can't find the rule that defines . What is it ?

c) I can't find the rule that defines . What is it ?

2. Section 12.1 refers to a rule 

	factor = "(" expression ")" | variable-reference | function-call | unsigned-constant| "NOT" factor 
| "sign" factor | set-constructor | value-typecast | address-factor .


I can't find the rule  but it may be the same as the rule  given in 
section 12.7 ?


	addressfactor = "@" ( variable-reference | procedure-identifier | function-identifier | 
qualified-method-identifier ) .


3. Section 2.2 refers to a rule 

	typed-constant = constant | address-constant | array-constant | record-constant | 
procedural-constant .


I can't find the rule . What is it ?

4. Section 2.2 also refers to a rule 

	typed-constant = constant | address-constant | array-constant | record-constant | 
procedural-constant .


I can't find the rule . What is it ?

5. Section 2.2 also refers to a rule 

	typed-constant = constant | address-constant | array-constant | record-constant | 
procedural-constant .


I can't find the rule . What is it ?

6. Section 2.2 also refers to a rule 

	typed-constant = constant | address-constant | array-constant | record-constant | 
procedural-constant .


I can't find the rule . What is it ?

7. Section 13.3 refers to a rule 

asm-statement = "asm" assembler-code "END" [ registerlist ] .

I can't find a rule for  What is it, from the point of view of 
parsing Pascal ?

8. Section 10.1 refers to  a rule 

	helper-type = ( "CLASS" | "RECORD" | "TYPE" ) "helper" [ "(" basehelper ")" ] "FOR" identifier  { 
helper-component-list } "END" hint-modifiers .


I can't find a rule for . What is it ?

9. Sections 17.2 and 6.1 refer to a rule 

exception-handler = "ON" [ identifier ":" ] class-type-identifier "DO" 
statement .
class-heritage = "(" class-type-identifier [ class-implemented-interfaces ] 
")" .

I can assume ?

class-type-identifier = identifier .

10. Section 11.2 refers to a rule 

objc-class-heritage = "(" [ objective-Cclass-type-identifier ] [ 
objc-implemented-protocols ] ")" .

I can assume ?

objective-Cclass-type-identifier = identifier .

11. Section 6.1 refers to a rule 

class-reference-type = "CLASS" "OF" classtype .

I can't find a rule for . What is it ?

12. Section 13.2 refers to a rule 

	structured-statement = compound-statement | conditional-statement | repetitive-statement | 
with-statement | exception-statement .


I can't find a rule for . What is it ?

13. Section 6.1 referes to a rule 

	component-list = [ visibility-specifier ] { field-definition } { const-declaration-part | 
type-declaration-part | variable-declaration-part | class-variable-declaration-part | 
method-definition | property-definition } .


I can assume ?

const-declaration-part = constant-declaration-part .

14. Sections 2.2, 3.1.1, 3.3.2, 4.7 and 13.2.2 refer to a rule 

	typed-constant = constant | address-constant | array-constant | record-constant | 
procedural-constant .

subrange-type = constant ".." constant .
variant = constant { "," constant } ":" "(" [ field-list ] ")" .
default-specifier = "default" [ constant ] | "nodefault" .
stored-specifier = "stored" ( constant | identifier ) .
case = constant [ ".." constant ] { "," constant [ ".." constant ] } 
":" statement .

I can't find a rule for . What is it ?

15. Sections 5.1 and 6.6.1 refer to a rule 

const-definition = "CONST" identifier "=" constant-expression ";" .
	class-method-directives = ( ( "virtual" | "dynamic" ) [ ";" "abstract" ] | "reintroduce" ";" | 
"override" ";" | "message" constant-expression ) [ call-modifiers ";" ] .


I can assume ?

constant-expression = expression .

16. Section 12.1 refers to a rule 

unsigned-constant = unsigned-number | character-string | constant-identifier | 
"NIL" .

I can assume ?

constant-identifier = identifier .

(more to follow)

Regards,

Adriaan van Os

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] case statement

2023-12-16 Thread Michael Van Canneyt via fpc-pascal




On Fri, 15 Dec 2023, Adriaan van Os wrote:


Michael Van Canneyt via fpc-pascal wrote:


The fact that the semicolon before the else is optional ?


I don't see a semicolon in the formal syntax.


This works:


OK, than an optional semicolon must be added to the  rule

exceptionhandlers =  [ exception-handler { ";" exception-handler } [ ";" ] [ 
"ELSE" statement-list ] | statement-list ] .


Well, you can have ; as well.

It means exception-handler can be empty in your repeat:

{ ';' [exception-handler] }

Or the whole ; is simply sloppyness on the part of the compiler.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] method-definition

2023-12-16 Thread Michael Van Canneyt via fpc-pascal



On Sat, 16 Dec 2023, Hairy Pixels via fpc-pascal wrote:





On Dec 15, 2023, at 8:56 PM, Adriaan van Os via fpc-pascal 
 wrote:

What complicates things, is that many conflicting rules have the same name in 
the Language Reference. For example, conceptually we have object-methods, 
record-methods, class-methods, interface-methods and objcclass-methods. But 
only the record method rules are prefixed as such.


You mean like why records require you to add "static" to class methods? Makes 
no sense to me either.


Well, I guess the explanation is something like the following:

Because class methods normally get a TClass pointer (a class reference) as Self 
unless you
specify self (in which case they become normal records).

Since records do not have a TClass concept, this 'Self' cannot be passed. 
To be consistent with classes and to make this explicit, the 'static' is

required.

In my opinion this is superfluous, but embarcadero decided otherwise.

The requirement for parameters in record constructors I guess comes from C++ builder by Embarcadero. 
There are some limitations imposed by C++.


Whether they could be dropped in FPC is something Sven Barth should answer.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal