Appendix 12--Generic Modula-2 Syntax

The term Generic Modula-2 refers to a set of extensions to the base language that allow for programmers to create and refine generic separate modules or templates.

A12.1 Keywords

The word GENERIC is added to the list of keywords for the base language.

A12.2 Diagrams of Changes to Base Language Syntax

compilation module (see A.2.2.1.1)

local module declaration (see A.2.2.2.9)

A12.3 Generic Modula-2 Syntax Diagrams

A12.3.1 Generic Definition Module

generic definition module

A12.3.2 Generic Implementation Module

generic implementation module

A12.3.3 Refining Definition Module

refining definition module

A12.3.4 Refining Implementation Module

refining implementation module

A12.3.5 Identifiers and Formal Parameters

generic separate module identifier

formal module parameters

formal module parameter list

formal module parameter

constant value parameter specification

type parameter specification

A12.3.6 Refining Local Module Declaration

refining local module declaration (see A.2.2.2.9)

A12.3.7 Actual Parameters

actual modual parameters

formal module parameter list

actual parameter

A12.4 Changes To the Syntax of the Base Language in EBNF

keyword = base language keyword | "GENERIC" ;

compilation module = program module | definition module |
implementation module | generic definition module | generic
implementation module | refining definition module | refining
implementation module ;

local module declaration = Base Language local module
declaration | refining local module declaration ;

A12.5 The Syntax of Generic Modula-2 in EBNF

The concrete syntax in this section is taken from ISO/IEC IS 10514-2, the international standard for the generic extensions to Modula-2.

generic definition module =
   "GENERIC", "DEFINITION", "MODULE", module identifier, [formal module parameters], semicolon,
   import lists, definitions,
   "END", module identifier, period ;
generic implementation module =
   "GENERIC", "IMPLEMENTATION", "MODULE", module identifier, [interrupt protection], [formal module parameters], semicolon,
   import lists, module block,
   module identifier, period ;
refining definition module =
  "DEFINITION", "MODULE", module identifier, equals, generic separate module identifier, [actual module parameters], semicolon,
   "END", module identifier, period ;
refining implementation module =
   "IMPLEMENTATION", "MODULE", module identifier, equals, generic separate module identifier, [actual module parameters], semicolon,
    "END", module identifier, period ;
generic separate module identifier =
  identifier ;
formal module parameters =
  left parenthesis, formal module parameter list, right parenthesis ;
formal module parameter list =
  formal module parameter, {semicolon, formal module parameter} ;
formal module parameter =
  constant value parameter specification| type parameter specification

constant value parameter specification = 
  identifier list, colon, formal type;
type parameter specification =
  identifier list, colon, "TYPE" ;
refining local module declaration =
   "MODULE", module identifier, equals, generic separate module identifier, [actual module parameters], semicolon,
   [export list],
   "END", module identifier ;
actual module parameters = 
  left parenthesis, actual module parameter list, right parenthesis ;
actual parameter list = 
  actual parameter, {comma, actual parameter} ;
actual parameter = 
  constant expression | type parameter ;

Contents