[fpc-pascal] More syntax questions (and more to follow)
Michael Van Canneyt
michael at freepascal.org
Sat Dec 16 13:00:03 CET 2023
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 <raise-statement> and <exception-address>
>
> raise-statement = "raise" [ exception-instance [ exception-address ]
> ] .
> exception-address = "at" exception-address [ "," address-expression ]
> .
>
> a) Is it correct that <exception-address> defines itself recursively ?
No.
That should be exception-address = "at" address-factor
Corrected.
>
> b) I can't find the rule that defines <address-expression>. What is it ?
Typo, should be address-factor.
Corrected.
>
> c) I can't find the rule that defines <exception-instance>. What is it ?
An expression of type exception.
Added.
>
> 2. Section 12.1 refers to a rule <address-factor>
>
> factor = "(" expression ")" | variable-reference | function-call |
> unsigned-constant| "NOT" factor | "sign" factor | set-constructor |
> value-typecast | address-factor .
>
> I can't find the rule <address-factor> but it may be the same as the rule
> <addressfactor> 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 <address-constant>
>
> typed-constant = constant | address-constant | array-constant |
> record-constant | procedural-constant .
>
> I can't find the rule <address-constant>. What is it ?
A constant of type address. So either Nil or @identifier.
>
> 4. Section 2.2 also refers to a rule <array-constant>
>
> typed-constant = constant | address-constant | array-constant |
> record-constant | procedural-constant .
>
> I can't find the rule <array-constant>. What is it ?
A constant of type array, obviously.
Needs to be added.
>
> 5. Section 2.2 also refers to a rule <record-constant>
>
> typed-constant = constant | address-constant | array-constant |
> record-constant | procedural-constant .
>
> I can't find the rule <record-constant>. What is it ?
A constant of type record.
Needs to be added.
>
> 6. Section 2.2 also refers to a rule <procedural-constant>
>
> typed-constant = constant | address-constant | array-constant |
> record-constant | procedural-constant .
>
> I can't find the rule <procedural-constant>. What is it ?
Address-factor of procedural type.
Needs to be added.
>
> 7. Section 13.3 refers to a rule <assembler code>
>
> asm-statement = "asm" assembler-code "END" [ registerlist ] .
>
> I can't find a rule for <assembler code> 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 <basehelper>
>
> helper-type = ( "CLASS" | "RECORD" | "TYPE" ) "helper" [ "("
> basehelper ")" ] "FOR" identifier { helper-component-list } "END"
> hint-modifiers .
>
> I can't find a rule for <basehelper>. What is it ?
An identifier.
Corrected.
>
> 9. Sections 17.2 and 6.1 refer to a rule <class-type-identifier>
>
> 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 <objective-Cclass-type-identifier>
>
> 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 <classtype>
>
> class-reference-type = "CLASS" "OF" classtype .
>
> I can't find a rule for <classtype>. What is it ?
class-type-identifier (or identifier)
Added.
>
> 12. Section 13.2 refers to a rule <conditional-statement>
>
> structured-statement = compound-statement | conditional-statement |
> repetitive-statement | with-statement | exception-statement .
>
> I can't find a rule for <conditional-statement>. What is it ?
You missed it. It is defined under 'Structured statements'.
>
> 13. Section 6.1 referes to a rule <const-declaration-part>
>
> 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 <constant>
>
> 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 <constant>. 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 <constant-expression>
>
> 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 <constant-identifier>
>
> unsigned-constant = unsigned-number | character-string |
> constant-identifier | "NIL" .
>
> I can assume ?
>
> constant-identifier = identifier .
Yes. Added.
Thanks for the questions. They showed me deficiencies of the text.
I have corrected what could be done quickly.
For the typed constants I need some time to correct/add them, since I need
to provide some explanatory text.
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.
Furthermore, recent changes in Delphi syntax unfortunately require that the
parser is aware of the types of some of the elements, something which cannot be
expressed in a formal syntax :/
As far as I know, Delphi no longer provides an up-to-date grammar.
The last one I saw came with Delphi 7.
Michael.
More information about the fpc-pascal
mailing list