Contents | Prev | Next | Index


Language Grammar

The syntax of Oberon-2 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 standard Oberon-2 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 ::= module

module         ::= program program_id ; package
                   import_list block <identifier> .
program        ::= foreign MODULE
foreign        ::= java_foreign                           
               ::= <empty>
program_id     ::= <identifier>
package        ::= java_package                           
               ::= <empty>
import_list    ::= import
               ::= <empty>
import         ::= IMPORT item_list ;
item_list      ::= item_list , item
               ::= item
item           ::= <identifier>
               ::= <identifier> := <identifier>

semicolon       ::= ;
                ::= ; java_throws
const_decl_list ::= const_decl_list const_decl ;
                ::= <empty>
const_def       ::= identdef = const_expr
var_decl_list   ::= var_decl_list var_decl ;
                ::= <empty>

const_decl      ::= const_def

var_decl       ::= var_ident_list : type
var_ident_list ::= var_ident_list , var_ident
               ::= var_ident
var_ident      ::= identdef
               ::= identdef [ <string> ]
               ::= identdef java_name

procedure_heading ::= procedure proc_id
                  ::= procedure proc_id formal_parameters
procedure         ::= modifier PROCEDURE
modifier          ::= java_modifiers                     
                  ::= <empty>                            
proc_id           ::= identdef
                  ::= receiver identdef
                  ::= identdef [ <string> ]
                  ::= receiver identdef [ <string> ]
                  ::= identdef java_name
                  ::= receiver identdef java_name
receiver          ::= ( VAR <identifier> : <identifier> )
                  ::= ( <identifier> : <identifier> )

formal_parameters ::= ( )
                  ::= ( ) : qualident
                  ::= ( fp_section_list )
                  ::= ( fp_section_list ) : qualident
fp_section_list   ::= fp_section_list ; fp_section
                  ::= fp_section
fp_section        ::= VAR id_list : formal_type
                  ::= id_list : formal_type
id_list           ::= id_list , <identifier>
                  ::= <identifier>
formal_type       ::= qualident
                  ::= open_array qualident
open_array        ::= open_array ARRAY OF
                  ::= ARRAY OF

qualident      ::= qualifier_list . <identifier>
               ::= <identifier>
qualifier_list ::= qualifier_list . qualifier
               ::= qualifier
ident_list     ::= ident_list , identdef
               ::= identdef
identdef       ::= <identifier>
               ::= <identifier> *
               ::= <identifier> -

block          ::= decl_seq END
               ::= decl_seq BEGIN stmt_seq END
decl_seq       ::= decl_list proc_decl_list
decl_list      ::= decl_list decl
               ::= <empty>
decl           ::= CONST const_decl_list
               ::= VAR var_decl_list
               ::= TYPE type_decl_list
type_decl_list ::= type_decl_list type_decl semicolon
               ::= <empty>
type_decl      ::= type_id = type
type_id        ::= identdef
               ::= identdef java_name
proc_decl_list ::= proc_decl_list procedure_decl ;
               ::= proc_decl_list forward_decl semicolon
               ::= <empty>
procedure_decl ::= procedure_heading semicolon
                   block <identifier>
forward_decl   ::= procedure forward_id
               ::= procedure forward_id formal_parameters
forward_id     ::= ^ proc_id

stmt_seq          ::= stmt_seq ; stmt
                  ::= stmt
stmt              ::= assignment
                  ::= procedure_call
                  ::= if_stmt
                  ::= case_stmt
                  ::= while_stmt
                  ::= repeat_stmt
                  ::= for_stmt
                  ::= loop_stmt
                  ::= guard_stmt
                  ::= EXIT
                  ::= return_stmt
                  ::= <empty>

assignment        ::= left_designator := expr
left_designator   ::= designator

procedure_call    ::= proc_designator
                  ::= proc_designator actual_parameters
proc_designator   ::= designator
actual_parameters ::= ( param_list )
                  ::= ( )
param_list        ::= param_list , param_expr
                  ::= param_expr
param_expr        ::= expr

if_stmt           ::= IF boolean_expr then_stmt
                      elsif_stmt_list else_stmt END
boolean_expr      ::= expr
then_stmt         ::= THEN stmt_seq
elsif_stmt_list   ::= elsif_stmt_list elsif_stmt
                  ::= <empty>
elsif_stmt        ::= ELSIF boolean_expr THEN stmt_seq
else_stmt         ::= ELSE stmt_seq
                  ::= <empty>
case_stmt         ::= switch_expr case_list else_case END
switch_expr       ::= CASE expr OF
case_list         ::= case_list | case
                  ::= case
case              ::= case_label_list : stmt_seq
                  ::= <empty>
case_label_list   ::= case_label_list , case_label
                  ::= case_label
case_label        ::= const_expr .. const_expr
                  ::= const_expr
else_case         ::= ELSE stmt_seq
                  ::= <empty>
while_stmt        ::= WHILE boolean_expr DO stmt_seq END
repeat_stmt       ::= REPEAT stmt_seq UNTIL boolean_expr
loop_stmt         ::= LOOP stmt_seq END
for_stmt          ::= FOR control_list DO stmt_seq END
control_list      ::= control_assignment to_expr by_expr
control_assignment ::= control_var := expr
control_var       ::= <identifier>
to_expr           ::= TO expr
by_expr           ::= BY const_expr
                  ::= <empty>
guard_stmt        ::= WITH guard_expr first_guard
    elsif_guard_list else_guard END
first_guard      ::= DO stmt_seq
guard_expr       ::= qualident : qualident
elsif_guard_list ::= elsif_guard_list elsif_guard
                 ::= <empty>
elsif_guard       ::= | guard_expr DO stmt_seq
else_guard       ::= ELSE stmt_seq
                 ::= <empty>
return_stmt ::= RETURN ::= RETURN expr const_expr ::= expr expr ::= simple_expr relation simple_expr ::= simple_expr simple_expr ::= simple_expr add_operator term ::= term ::= unary term term ::= term mul_operator factor ::= factor factor ::= <character> ::= <integer> ::= <real> ::= <string> ::= set ::= designator ::= func_designator actual_parameters ::= ( expr ) ::= ~ factor set ::= { elem_list } ::= { } elem_list ::= elem_list , elem ::= elem elem ::= elem_expr .. elem_expr ::= elem_expr elem_expr ::= expr func_designator ::= designator relation ::= = ::= # ::= < ::= <= ::= > ::= >= ::= IN ::= IS add_operator ::= + ::= - ::= OR mul_operator ::= * ::= / ::= DIV ::= MOD ::= & unary ::= + ::= - designator ::= designator_id selector_list ::= designator_id designator_id ::= qualident selector_list ::= selector_list selector ::= selector selector ::= . <identifier> ::= [ index_list ] ::= ^ ::= ( qualident ) index_list ::= index_list , index ::= index index ::= expr type ::= simple_type ::= array_type ::= record_type ::= pointer_type ::= procedure_type simple_type ::= qualident array_type ::= ARRAY length_list OF type length_list ::= length_list , length ::= length length ::= const_expr record_type ::= record field_list_seq END ::= record record_base field_list_seq END record ::= modifier RECORD record_base ::= ( parent interface_list ) parent ::= qualident ::= <empty> interface_list ::= interface_list , qualident ::= <empty> field_list_seq ::= field_list_seq ; field_list ::= field_list field_list ::= modifier field_id_list : type ::= <empty> field_id_list ::= field_id_list , field_name ::= field_name field_name ::= identdef ::= identdef java_name pointer_type ::= POINTER TO type ::= POINTER TO open_array type procedure_type ::= procedure formal_parameters ::= procedure

The following comment-embedded compiler directives are only accepted at certain places of an Oberon-2 module and are treated by the above described Oberon-2 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 Oberon-2 for JVM  (Last documentation update Jun 2, 2000)
Copyright © 1998 Mill Hill & Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to mhc@webcom.com