Contents | Prev | Next | Index
The syntax of Pascal can be described using a simplified grammar notation, see section Syntax for further information on how to read it. Some language constructs are an extension to Pascal and are shown here in a red color. These extensions are usually not needed unless foreign Java classes are being imported and used.
compilation_unit ::= unit_module
::= program_module
unit_module ::= def_module imp_module
program_module ::= program_heading import_list block .
def_module ::= unit_heading INTERFACE import_list def_list
unit_heading ::= unit <identifier> ; package
unit ::= foreign UNIT
foreign ::= java_foreign
::= <empty>
package ::= java_package
::= <empty>
imp_module ::= IMPLEMENTATION import_list imp_block .
imp_block ::= decl_list END
::= decl_list
INITIALIZATION stmt_seq END
::= decl_list
INITIALIZATION stmt_seq
FINALIZATION stmt_seq END
program_heading ::= PROGRAM program_id ; package
::= PROGRAM program_id program_parameters ; package
::= LIBRARY program_id ; package
::= <empty>
program_id ::= <identifier>
program_parameters ::= ( ident_list )
import_list ::= USES item_list ;
::= <empty>
item_list ::= item_list , item
::= item
item ::= <identifier>
def_list ::= def_list def
::= <empty>
def ::= CONST const_decl_list
::= TYPE type_def_list
::= VAR var_decl_list
::= procedure_heading semicolon
::= func_heading semicolon
semicolon ::= ;
::= ; java_throws
const_decl_list ::= const_decl_list const_decl ;
::= <empty>
const_def ::= <identifier> = const_expr
type_def_list ::= type_def_list type_def ;
::= <empty>
type_def ::= type_decl
var_decl_list ::= var_decl_list var_decl ;
::= <empty>
const_decl ::= const_def
::= const_var_decl = typed_const
const_var_decl ::= const_var_id : type
const_var_id ::= ident
typed_const ::= primary
::= array_const
::= record_const
array_const ::= ( const_list )
const_list ::= const_list , element_const
::= element_const
element_const ::= typed_const
record_const ::= ( field_const_list )
field_const_list ::= field_const_list ; field_const
::= field_const
field_const ::= field_id : typed_const
::= <empty>
field_id ::= <identifier>
var_decl ::= var_ident_list : type
var_ident_list ::= var_ident_list , var_ident
::= var_ident
var_ident ::= ident
::= ident [ <string> ]
::= ident java_name
procedure_heading ::= procedure proc_id
::= procedure proc_id formal_parameters
::= constructor proc_id
::= constructor proc_id formal_parameters
::= destructor proc_id
::= destructor proc_id formal_parameters
procedure ::= modifier PROCEDURE
constructor ::= modifier CONSTRUCTOR
destructor ::= modifier DESTRUCTOR
modifier ::= java_modifiers
::= <empty>
proc_id ::= ident
::= ident . member_id
::= ident [ <string> ]
::= ident . member_id [ <string> ]
::= ident java_name
::= ident . member_id java_name
formal_parameters ::= ( fp_section_list )
fp_section_list ::= fp_section_list ; fp_section
::= fp_section
fp_section ::= VAR ident_list : formal_type
::= ident_list : formal_type
::= CONST ident_list : formal_type
::= VAR ident_list
formal_type ::= qualident
::= open_array qualident
::= open_array CONST
::= STRING
::= open_array STRING
::= FILE
::= open_array FILE
open_array ::= ARRAY OF
func_heading ::= function proc_id func_parameters
function ::= modifier FUNCTION
func_parameters ::= : result_type
::= ( fp_section_list ) : result_type
result_type ::= qualident
::= STRING
qualident ::= qualifier_list . ident
::= ident
qualifier_list ::= qualifier_list . qualifier
::= qualifier
ident_list ::= ident_list , ident
::= ident
block ::= decl_list END
::= decl_list BEGIN stmt_seq END
decl_list ::= decl_list decl
::= <empty>
decl ::= CONST const_decl_list
::= TYPE type_decl_list
::= VAR var_decl_list
::= procedure_decl ;
::= func_decl ;
::= exports
::= LABEL label_list ;
type_decl_list ::= type_decl_list type_decl semicolon
::= <empty>
type_decl ::= type_id = type
::= type_id = CLASS
type_id ::= ident
::= ident java_name
procedure_decl ::= procedure_heading semicolon subroutine
::= class_directive procedure_heading semicolon subroutine
subroutine ::= param_directive block
::= param_directive FORWARD
::= param_directive external
param_directive ::= REGISTER ;
::= PASCAL ;
::= CDECL ;
::= STDCALL ;
::= <empty>
external ::= EXTERNAL
::= EXTERNAL <string>
::= EXTERNAL <string> NAME <string>
::= EXTERNAL <string> INDEX <integer>
func_decl ::= func_heading semicolon subroutine
::= class_directive func_heading semicolon subroutine
exports ::= EXPORTS exports_list ;
exports_list ::= exports_list exports_entry
::= exports_entry
exports_entry ::= <identifier> exports_index
exports_name exports_resident
exports_index ::= INDEX <integer>
::= <empty>
exports_name ::= NAME <string>
::= <empty>
exports_resident ::= RESIDENT
::= <empty>
label_list ::= label_list , label
::= label
label ::= <integer>
::= <identifier>
stmt_seq ::= stmt_seq ; stmt
::= stmt
stmt ::= assignment
::= procedure_call
::= if_stmt
::= case_stmt
::= while_stmt
::= repeat_stmt
::= for_stmt
::= with_stmt
::= raise_stmt
::= try_except_stmt
::= try_finally_stmt
::= compound_stmt
::= goto_stmt
::= label_stmt
::= <empty>
assignment ::= left_designator := expr
left_designator ::= expr_designator
::= @ expr_designator
::= sub_expr selector_list
expr_designator ::= designator
::= func_var_ref
func_var_ref ::= func_result selector_list
func_result ::= proc_designator actual_parameters
procedure_call ::= proc_designator
::= proc_designator actual_parameters
proc_designator ::= expr_designator
actual_parameters ::= ( param_list )
param_list ::= param_list , param_expr
::= param_expr
param_expr ::= expr
::= expr : precision
::= expr : precision : precision
precision ::= expr
if_stmt ::= IF boolean_expr then_stmt else_stmt
::= IF boolean_expr then_stmt
boolean_expr ::= expr
then_stmt ::= THEN stmt
else_stmt ::= ELSE stmt
case_stmt ::= switch_expr case_list else_case endcase
::= switch_expr case_list endcase
switch_expr ::= CASE expr OF
case_list ::= case_list ; case
::= case
case ::= case_label_list : stmt
case_label_list ::= case_label_list , case_labels
::= case_labels
case_labels ::= const_expr .. const_expr
::= const_expr
else_case ::= ELSE stmt
::= ; ELSE stmt
endcase ::= END
::= ; END
while_stmt ::= WHILE boolean_expr DO stmt
repeat_stmt ::= REPEAT stmt_seq UNTIL boolean_expr
for_stmt ::= FOR control_list DO stmt
control_list ::= control_assignment by_expr to_expr
control_assignment ::= control_var := expr
control_var ::= <identifier>
to_expr ::= expr
by_expr ::= TO
::= DOWNTO
with_stmt ::= WITH rec_designators DO stmt
rec_designators ::= rec_designators , rec_designator
::= rec_designator
rec_designator ::= expr
raise_stmt ::= RAISE exception_instance
::= RAISE
exception_instance ::= expr
try_except_stmt ::= try_except_part exception_block END
try_except_part ::= try stmt_seq except
try ::= TRY
except ::= EXCEPT
exception_block ::= exception_handlers default_handler
::= exception_handlers
::= stmt_seq
::= exception_handlers ; default_handler
::= exception_handlers ;
exception_handlers ::= exception_handlers ; exception_handler
::= exception_handler
exception_handler ::= ON exception_id DO stmt
on ::= ON
exception_id ::= <identifier> : class_id
::= class_id
class_id ::= qualident
default_handler ::= ELSE stmt_seq
try_finally_stmt ::= TRY stmt_seq FINALLY stmt_seq END
compound_stmt ::= BEGIN stmt_seq END
goto_stmt ::= GOTO label
label_stmt ::= label :
const_expr ::= expr
expr ::= simple_expr relation simple_expr
::= simple_expr
simple_expr ::= simple_expr add_operator term
::= term
term ::= term mul_operator factor
::= factor
factor ::= primary
::= sub_expr
::= sub_expr selector_list
sub_expr ::= ( expr )
primary ::= chr_const
::= <integer>
::= <real>
::= <string>
::= set
::= expr_designator
::= proc_designator actual_parameters
::= not factor
::= unary factor
::= @ expr_designator
set ::= [ elem_list ]
::= [ ]
elem_list ::= elem_list , elem
::= elem
elem ::= elem_expr .. elem_expr
::= elem_expr
elem_expr ::= expr
relation ::= =
::= <>
::= <
::= <=
::= >
::= >=
::= IN
::= IS
add_operator ::= +
::= -
::= OR
::= XOR
mul_operator ::= *
::= /
::= DIV
::= MOD
::= AND
::= SHL
::= SHR
::= AS
not ::= NOT
unary ::= +
::= -
designator ::= designator_id selector_list
::= designator_id
designator_id ::= qualident
::= INHERITED <identifier>
selector_list ::= selector_list selector
::= selector
selector ::= . <identifier>
::= [ index_list ]
::= ^
index_list ::= index_list , index
::= index
index ::= expr
type ::= simple_type
::= string_type
::= pointer_type
::= procedure_type
::= PACKED structured_type
::= structured_type
structured_type ::= array_type
::= record_type
::= set_type
::= file_type
::= class_ref_type
::= class_type
simple_type ::= qualident
::= enumeration
::= subrange_type
enumeration ::= ( enum_list )
enum_list ::= enum_list , <identifier>
::= <identifier>
subrange_type ::= const_expr .. const_expr
string_type ::= STRING
::= STRING [ const_expr ]
array_type ::= ARRAY [ index_type_list ] OF type
index_type_list ::= index_type_list , index_type
::= index_type
index_type ::= simple_type
record_type ::= record field_seq END
record ::= modifier RECORD
field_seq ::= fixed_part
::= fixed_part ; variant_part
::= variant_part
::= fixed_part ;
::= fixed_part ; variant_part ;
::= variant_part ;
::= <empty>
fixed_part ::= fixed_part ; field_list
::= field_list
field_list ::= modifier field_id_list : type
field_id_list ::= field_id_list , field_name
::= field_name
field_name ::= member_id
::= member_id java_name
variant_part ::= CASE tag OF variant_list
tag ::= qualident
::= field_name : qualident
variant_list ::= variant_list ; variant
::= variant
variant ::= variant_label_list : ( field_seq )
variant_label_list ::= variant_label_list , variant_labels
::= variant_labels
variant_labels ::= const_expr
set_type ::= SET OF simple_type
pointer_type ::= ^ pointee_type
::= ^ open_array pointee_type
pointer_to ::= ^
pointee_type ::= qualident
file_type ::= FILE OF type
::= FILE
procedure_type ::= procedure formal_parameters
::= procedure
::= function func_parameters
class_ref_type ::= CLASS OF qualident
class_type ::= class class_base component_seq END
class ::= java_modifiers CLASS
::= CLASS
class_base ::= ( parent interface_list )
::= <empty>
parent ::= qualident
::= <empty>
interface_list ::= interface_list , qualident
::= <empty>
component_seq ::= component_seq visibility component_list
::= component_list
visibility ::= PUBLISHED
::= PUBLIC
::= PROTECTED
::= PRIVATE
::= AUTOMATED
component_list ::= field_def_list method_list
::= field_def_list
::= method_list
::= <empty>
field_def_list ::= field_def_list field_list ;
::= field_list ;
method_list ::= method_list method_def
::= method_def
method_def ::= method_heading semicolon method_directives
method_heading ::= procedure_heading
::= func_heading
::= class_directive procedure_heading
::= class_directive func_heading
class_directive ::= CLASS
method_directives ::= virtual param_directive abstract
virtual ::= VIRTUAL ;
::= DYNAMIC ;
::= OVERRIDE ;
::= <empty>
abstract ::= ABSTRACT ;
::= <empty>
The following comment-embedded compiler directives are only accepted at certain places of a Pascal unit or program and are treated by the above described Pascal language grammar like terminal tokens. They are shown here in red.
java_foreign ::= (*$JAVA FOREIGN *)
java_package ::= (*$JAVA PACKAGE <string> *)
java_throws ::= (*$JAVA THROWS exception_list *)
exception_list ::= exception_list , <identifier>
::= <identifier>
java_name ::= (*$JAVA NAME <string> *)
java_modifiers ::= (*$JAVA modifier_list *)
modifier_list ::= modifier_list modifier
::= modifier
modifier ::= PUBLIC
::= PROTECTED
::= PRIVATE
::= ABSTRACT
::= STATIC
::= FINAL
::= TRANSIENT
::= VOLATILE
::= SYNCHRONIZED
::= NATIVE
::= INTERFACE
::= CONSTRUCTOR
Contents | Prev | Next | Index
Canterbury Pascal for JVM (Last documentation update
Jun 9, 2000)
Copyright © 1998 Mill Hill & Canterbury
Corporation, Ltd. All rights reserved
Please send any comments or corrections to
mhc@webcom.com