Appendix A
Pascal grammar

Below is a formal grammar of the pascal language in EBNF notation. It is not 100% complete, some parts such as assembler or objective-c have not been specified.

⟨module⟩ = ⟨programxmodule⟩ | ⟨libraryxmodule⟩ | ⟨packagexmodule⟩ | ⟨unitxmodule⟩ ;
⟨programxmodule⟩ = ⟨programxheader⟩ ”;” [ ⟨fullxusesxclause⟩ ] ⟨block⟩ ”.” ;

⟨programxheader⟩ = ”program ” ⟨identifier⟩ [ ” (” ⟨programxparameters⟩ ”)” ] ;

⟨programxparameters⟩ = ⟨identifierxlist⟩ ;

⟨fullxusesxclause⟩ = ”uses” ⟨fullxusesxitem ⟩ ”,” ⟨fullxusesxitem ⟩ ”;” ;

⟨fullxusesxitem⟩ = ⟨identifier⟩ [ ”in” ⟨stringxliteral⟩ ] ;

⟨libraryxmodule⟩ = ⟨libraryxheader⟩ ”;” [ ⟨usesxclause⟩ ] ⟨block⟩ ”.” ;

⟨libraryxheader⟩ = ”library” ⟨identifier⟩ ;

⟨packagexmodule⟩ = ⟨packagexheader⟩ ”;” [ ⟨containsxclause⟩ ] [⟨requiresxclause⟩] ”end ”
    ”.” ;

⟨packagexheader⟩ = ”package ” ⟨identifier⟩ ;

⟨containsxclause⟩ = ”contains” ⟨fullxusesxitem⟩ ”,” ⟨fullxusesxitem⟩ ”;” ;

⟨requiresxclause⟩ = ”requires” ⟨qualifierxlist⟩ ”;” ;

⟨unitxmodule⟩ = ⟨unitxheader⟩⟨interfacexsection⟩⟨implementationxsection⟩( [⟨initializationxsection ⟩
    ] [ ⟨finalizationxsection ⟩ ]
 |  ”begin” ⟨statementxlist⟩ ) ”end” ”.” ;

⟨unitxheader⟩ = ”unit” ⟨qualifier⟩ [ ⟨hintdirectives⟩ ] ”;” ;
⟨interfacexsection⟩ = ”interface” [ ⟨usesxclause⟩ ] [⟨interfacexparts⟩ ] ;

⟨usesxclause⟩ = ”uses” ⟨identifier⟩ ”,” ⟨identifier⟩ ”;” ;

⟨interfacexparts⟩ = ⟨interfacexpart⟩ ⟨interfacexpart⟩ ;

⟨interfacexpart⟩ = ⟨constantxdeclarationxblock ⟩
 |  ⟨typexdeclarationxblock⟩
 |  ⟨variablexdeclarationxblock⟩
 |  ⟨propertyxdeclarationxblock⟩
 |  ⟨procedurexheadersxblock⟩ ;

⟨implementationxsection⟩ = ”implementation ” [ ⟨usesxclause⟩ ] ⟨declarationxpart⟩ ;

⟨initializationxsection⟩ = ”initialization ” ⟨statementxlist⟩ ;

⟨finalizationxsection⟩ = ”finalization” ⟨statementxlist⟩ ;

⟨exportsxclause⟩ = ”exports” ⟨exportsxlist⟩ ”;” ;

⟨exportsxlist⟩ = ⟨exportsxentry⟩ ”,” ⟨exportsxentry⟩ ;

⟨exportsxentry⟩ = ⟨identifier⟩ [ ”index ” ⟨integerxconstant⟩ ] [ ”name ” ⟨stringxconstant⟩ ]
    ;

⟨procedurexheadersxblock⟩ = ⟨procedurexheader⟩
 |  ⟨functionxheader⟩
 |  ⟨operatorxheader⟩;

⟨procedurexheader⟩ = ⟨genericxprocedurexheader⟩
 |  ⟨regularxprocedurexheader⟩ ;

⟨genericxprocedurexheader⟩ = ”generic” ”procedure ” ⟨qualifier⟩ ⟨genericxtemplatexlist⟩
    ⟨formalxparameterxlist⟩ ”;” [ ⟨callxmodifiers⟩ ”;” ] [⟨hintdirectives⟩] ;

⟨regularxprocedurexheader⟩ = ”procedure ”⟨qualifier⟩[⟨genericxtemplatexlist⟩]⟨formalxparameterxlist⟩
    ”;” [ ⟨callxmodifiers⟩ ”;” ] [⟨hintdirectives⟩] ;
⟨functionxheader⟩ = ⟨genericxfunctionxheader⟩
 |  ⟨regularxfunctionxheader⟩ ;

⟨genericxfunctionxheader⟩ = ”generic” ”function” ⟨qualifier⟩[”¡” ⟨genericxtemplatexlist⟩
    ”¿” ] ⟨formalxparameterxlist⟩ ”:” ⟨type⟩ [ ⟨callxmodifiers⟩ ”;” ] [⟨hintdirectives⟩] ;

⟨regularxfunctionxheader⟩ = ”function” ⟨qualifier⟩ [” ¡” ⟨genericxtemplatexlist⟩”¿” ]⟨formalxparameterxlist⟩
    ”:” ⟨type⟩ [ ⟨callxmodifiers⟩ ”;” ] [⟨hintdirectives⟩] ;

⟨operatorxheader⟩ = ”operator” ⟨operatorxdefinition⟩ [ ⟨resultxidentifier ⟩ ] ”:” ⟨type⟩ ;

⟨operatorxdefinition⟩ = ⟨assignmentxoperatorxdefinition ⟩
 |  ⟨arithmeticxoperatorxdefinition⟩
 |  ⟨comparisonxoperatorxdefinition⟩
 |  ⟨logicalxoperatorxdefinition⟩
 |  ⟨otherxoperatorxdefinition⟩ ;

⟨genericxtemplatexlist⟩ = ⟨constrainedxtemplatexlist⟩
 |  ⟨freextemplatexlist⟩ ;

⟨constrainedxtemplatexlist⟩ = ⟨constrainedxtemplates⟩ ”;” ⟨constrainedxtemplates⟩ ;

⟨freextemplatexlist⟩ = ⟨identifier⟩ ”,” ⟨qualifier⟩ ;

⟨constrainedxtemplates⟩ = ⟨identifierxlist⟩ ”:” ⟨typexconstraint⟩ ”,” ⟨typexconstraint⟩ ;

⟨identifierxlist⟩ = ⟨identifier⟩ ”,” ⟨identifier⟩ ;

⟨typexconstraint⟩ = ⟨identifier⟩
 |  ”class”
 |  ”record” ;

⟨block⟩ = ⟨declarationxblock⟩ ⟨statementxblock⟩ ;

⟨declarationxblock⟩ = ⟨labelxdeclarationxblock⟩
 |  ⟨constantxdeclarationxblock⟩
 |  ⟨resourcestringxdeclarationxblock⟩
 |  ⟨classxfuncxprocxdeclarationxblock⟩
 |  ⟨funcxprocxdeclarationxblock⟩
 |  ⟨typexdeclarationxblock⟩
 |  ⟨variablexdeclarationxblock⟩
 |  ⟨threadvariablexdeclarationxblock⟩
 |  ⟨exportsxclause⟩ ;
⟨funcxprocxdeclarationxblock⟩ = ⟨procedurexdeclaration ⟩
 |  ⟨functionxdeclaration⟩
 |  ⟨constructorxdeclaration⟩
 |  ⟨destructorxdeclaration⟩
 |  ⟨operatorxdeclaration⟩ ;

⟨statementxblock⟩ = ⟨compoundxstatement ⟩ ;