This is the Free Pascal language diagrams page. The diagrams below present visual representations of the Free Pascal language rules. At this time not all rule diagrams have been posted. If you find an error or would like to add new diagrams, you can use the edit this page function to alter or add new diagrams.
These are common shapes and their meanings used used in the diagrams. The link shape navigates to other diagrams when clicked.
End of line which varies by platform.
The following single and paired symbols have special. In the diagrams to follow the open and close parenthesis symbols are not always shown. For example in the (7 + 4) * 2 expression the number constant diagram omits these types the parenthesis.
An operator is any of the following symbols or keywords.
Letters include all upper and lower case characters A to Z along with the underscore character.
Digits include the characters 0 to 9.
Hexadecimal digits include the 0 to 9 digits plus the case insensitive characters A to F.
An integer literal is a series of digits beginning with an optional sign.
A hexadecimal begins with a dollar sign character and is followed by one or more hex digits.
A float literal begins with an optional sign. There must be at least one digit before the decimal point. An optional mantissa can be used to move the decimal point to the right with a positive sign and to the left with a negative sign.
The mantissa is used to raise or lower a floating point literal numbers by factors of 10.
A char literal can be used to specify characters which are either unprintable or easier to remember by character code.
A string is a chain of on or more characters. In Free Pascal literal strings begin and end with a ' single quote character or a series of one or more char literals. When spanning multiple lines in source code that can be joined using the + operator.
A boolean literal signifies a value or true or false.
An enumeration a collection of enumeration values surrounded by parenthesis.
A enumeration value is named identifier belonging to an enumeration which can be evaluated to a number. Enumeration values are assigned a number by the compiler unless specifically assigned a value by the programmer.
An ordinal is any of the following.
A subrange is the inclusive list of values between two ordinals. When defining a subrange the two underlying types must be matched. For example the subrange 'A'..'Z' is valid while 65..'Z' is not.
An identifier is must begin with at least one letter and can then be followed by any combination of letters or digits, but if cannot conflict with a keyword.
A dotted identifier an identifier that is optionally followed by several more identifiers separated by . dots.
A list of dotted identifiers that is optionally followed by several more dotted identifiers separated by , commas.
A comment is treated by the compiler like white space. Three comment styles are available. The single line comment style begins with // two forward slashes and is terminated by the first EOL marker. The other two styles can space across multiple lines. When comments are nested, the first comment style terminates the nested child comments.
A program starts with the keyword program and is followed by a dotted identifier.
A unit starts with the unit keyword and is followed by a dotted identifier.
A program is structured starting with a header, followed by a program block, and ending with a begin and end. with statements in between forming the main program entry point.
A unit is structured starting with a header followed by interface and implementation sections. The initialization section is optional.
The uses clause is an optional section that can be placed at the top of a program block or a unit's interface and implementation sections. It begins with the uses keyword and is followed by one or more unit names. The compiler searches it's include path to find unit files matching the names in the uses clause, then add their declarations to the current program or unit's namespace.
The program block starts with an optional uses clause which is followed by implementation code.
A unit's implementation section follows the interface section. It may have it's own uses clause which is followed by implementation code.
A unit may contain both initialization and finalization sections at its end. Each section may contain zero or more statements. The initialization section must precede the finalization section.
A unit's interface section can contain many declarations. Each declaration starts with a block from one of seven possible keywords: var threadvar const resourcestring type function procedure.
A unit's implementation section may contain new declarations which become private to the unit. It is required to provide implementation code for any functions or procedure in the previous section which haven't been marked with the external directive.
A local implementation can be used inside a function or procedure implementation. I follows the same rules as regular implementations, but threadvar and resourcestring are disallowed.
A char constant can be build using a char literal or a dotted identifiers which references another char constant by name.
A string constant can be build using a string literal or a dotted identifiers which references another string constant by name.
A number constant can be build using a number literal or a dotted identifiers that references another number constant by name. Integer math operations which can be fully evaluated at compile time are allowed.
A floating point constant can be build using a number literal, floating literal, or a dotted identifiers that references another float constant by name. Math operations which can be fully evaluated at compile time are allowed. Please note, this includes certain math functions not shown in the diagram.
A boolean constant can be build using a boolean literal or a dotted identifier which references another boolean constant by name. Boolean operatators can be applied to the constant.
A subrange constant is a collection of one or more subranges or ordinals of the same type separated by commas.
The only possible pointer constant is nil.
All of constants mentioned above can be group under the single name constant. A constant can be surrounded by an optional typecast when appropriate.
An identifier list is a series of one or more identifiers separated by commas.
A var block contains one or more variable declarations. Each variable has an identifier and a type. When a single identifier is used it can be assigned an initial value using a constant.
A const block contains one or more constant declarations. Each constant has an identifier and a constant value. When a type identifier is used it's possible to reassign the constant at runtime if assignable typed constants is enabled in the compiler.
Resource String Block
A function header includes the name of the function, optional generic arguments, an optional list of parameter, and returns a value of a given type name. It may have directives at the end such as calling convention or an external marker.
A procedure header includes the name of the procedure, optional generic arguments, and an optional list of parameter. Procedures do not declare a return value. They have the same options for directives as a function header.
A generic block is an optional argument to functions, procedure, and types. When used with functions or procedures it precedes the parameter list. When used with a type it follows the type identifier.
Constraints can be applied to a generic argument. The constraint can either be a list of heap allocated identifier names, or class which is short for the TObject identifier. When the constructor keyword is used the identifier type must provide a single constructor with no arguments. The keyword record can be used to constraint a generic argument to stack based types.
A function implementation can either appear in the program block or in a unit's implementation section. Variables, constants, types, and other procedures and functions can be nested inside a function. These items are known as local implementations and they are private to the function. A function implementation may contain statements between begin and end;
Note: the external directive cannot be used inside a function implementation.
Other than the procedure header, a procedure implementation is identical to a function implementation.
Other than the procedure header, a procedure implementation is identical to a function implementation.
A statement's trailing ; semicolon is optional when a single statement is used. When an if statement has an else clause the ; semicolon cannot be used at the close of the then statement. In all other situations the ; semicolon must be placed at the end of a statement.
A boolean expression one which ultimately resolves to a boolean value.
An ordinal expression one which ultimately resolves to an ordinal value.
A case statement contains one or more case conditions between the keywords of and end.
A case statement is a flow controls structure requiring an ordinal expression. Program flow is directed through a series of case conditions. When the result of the expression falls within the range of a case condition the flow moved to the statement attached to the condition. If no case condition matches the result of the expression flow can optionally be moved to an else statement.
A looping statement beginning for the for keyword and ending with either to or downto. Identifier must be local, and ordinal expression must evaluate to the same type as the identifier. The to or downto keyword must be followed by a statement.
For In Statement
A looping statement beginning for the for keyword and ending with do. Expression between the for and do must evaluate to an enumerable type. The do keyword must be followed by a statement.
The if statement is a flow control structure requiring a boolean expression. When the expression evaluates to True the flow moved to the then statement. When an optional else clause is provided flow is moved to it when the expression evaluates to False.
In situations where else is used, the then Statement must start with begin and close with end and the then statement's trailing ; semicolon must be omitted.
The while statement is a flow control structure requiring a boolean expression. Flow is repeatedly moved to the statement following do while the expression evaluates to True. If a Break procedure is encountered inside a while statement flow immediately stops and moves to the next statement following the while statement. If a Break procedure is encountered inside a while statement flow immediately moves to the beginning of the statement after the do keyword.
The repeat statement is a flow control structure requiring a boolean expression. Flow is moves to the statement after the repeat keyword and moves back the expression evaluates to True. If a Break procedure is encountered inside a while statement flow immediately stops and moves to the next statement following the while statement. If a Break procedure is encountered inside a while statement flow immediately moves to the beginning of the statement after the do keyword.
An assignment statement is one which copies a right value to a left value. The type of the right value must be compatible with that of the left. The expression on the left must resolve to a writable value. Writeable values are those which are variables, fields, properties, dereferened pointers, and when enabled writable typed constants.
A collection of dotted identifiers with optional, access and operators that does not contain an assignment := symbol.
Brackets [ < or up caret ^ used to access a property or data structure.
One or more expressions separated by a , command.
One or more identifier lists, opening with a $lt; angle bracket and closing with > angle bracket. Identifier lists may open other generic arguments.
A type alias creates another optionally strongly typed identifier based on a type identifier.