Pat.Terry@p101.f4.n494.z5.fidonet.org (Pat Terry) (01/16/90)
Recently a request was made by folk interested in the forthcoming Modula-2 standard for the EBNF of the Draft Proposal to be published in the net. This is part 1 of a 2 part posting in which this EBNF is presented. It has been transcribed from the D106 proposal, and there may be transcription errors. These are unintentional, and I apologise in advance for any that are my fault. Roger Henry, Chairman of the Wg13/Sc22 group, in giving permission to post this, has asked me to emphasize that (a) This represents syntax, not semantics. (b) The proposal is still subject to change (c) D106 is copyright by BSI (British Standards Institution) (d) Readers are urged to consult the draft proposal for further details I have identified what I suspect are some minor errors. There may be others, and interested readers are invited to comment on or query what errors or inconsistencies they think they may detect. Notwithstanding Roger's point (a), it will be noted that some measure of "semantic" information is implied in some of the non-terminal names. Partly because of this, there are far more productions than in PIM. The notation is different from that used in PIM, but should be easy to follow. At the level of "syntax" there are few discernable "differences" from the language in PIM, except for: (A5.5.1 and A5.5.2) array and record constructors - which are entirely new Underscores (lowlines) will be allowed in identifiers There is a proposal for a catenate operation to allow "strings" to be concatenated. There is a proposal to include the / and REM operators for whole number types ----------------------------------------------------------------------- COLLECTED MODULA-2 CONCRETE SYNTAX This version compiled 1 January 1990 by Pat Terry, from D106, appendix A and may not be 100% accurate. Any errors are, of course, unintentional A.1 Programs and Compilation Units A.1.1 Programs compilation unit = program module | definition module | implementation module ; A.1.2 Program Modules program module = "MODULE", module identifier, [ protection ], ";", import lists, module block, module identifier, "." ; module identifier = identifier ; protection = "[", constant expression, "]" ; constant expression = expression ; A.1.3 Definition Modules definition module = "DEFINITION", "MODULE", module identifier, ";", import lists, definitions, "END", module identifier, "." ; A.1.4 Implementation Modules implementation module = "IMPLEMENTATION", "MODULE", module identifier, [ protection ], ";", import lists, module block, module identifier, "." ; A.1.5 Module Blocks module block = declarations, [ "BEGIN", statement sequence ], "END" ; A.1.6 Import Lists import lists = { import list } ; import list = simple import | unqualified import ; A.1.6.1 Simple Imports simple import = "IMPORT", identifier list, ";" ; A.1.6.2 Unqualified Imports unqualified import = "FROM", module identifier, "IMPORT", identifier list, ";"; A.1.7 Export Lists export list = unqualified export | qualified export ; A.1.7.1 Unqualified Exports unqualified export = "EXPORT", identifier list, ";" ; A.1.7.2 Qualified Exports qualified export = "EXPORT", "QUALIFIED", identifier list, ";" ; A.2 Definitions and Declarations A.2.1 Definitions definitions = { definition } ; definition = "CONST", { constant declaration, ";" } | "TYPE", { type definition, ";" } | "VAR", { variable declaration, ";" } | procedure heading, ";" ; type definition = type declaration | opaque type definition ; procedure heading = proper procedure heading | function procedure heading ; opaque type definition = identifier ; A.2.2 Declarations declarations = { declaration } ; declaration = "CONST", { constant declaration, ";" } | "TYPE", { type declaration, ";" } | "VAR", { variable declaration, ";" } | procedure declaration, ";" | module declaration, ";" ; A.2.3 Constant Declarations constant declaration = identifier, "=", constant expression ; A.2.4 Type Declarations type declaration = identifier, "=", type ; A.2.5 Variable Declarations variable declaration = variable identifier list, ":", type ; variable identifier list = identifier, [ machine address ], { ",", identifier, [ machine address ] } ; machine address= "[", value of machine address or address type, "]" ; value of machine address or address type = constant expression ; A.2.6 Types type = type identifier | new type ; type identifier = qualified identifier ; A.2.7 New Types new type = enumeration type | subrange type | set type | pointer type | procedure type | array type | record type ; A.2.7.1 Enumeration Types enumeration type = "(", identifier list, ")" ; identifier list = identifier, { ",", identifier } ; A.2.7.2 Subrange Types subrange type = [ range type ], "[", constant expression, "..", constant expression, "]" ; range type = ordinal type identifier ; A.2.7.3 Set Types set type = "SET", "OF", base type ; base type = ordinal type ; ordinal type = qualified identifier | enumeration type | subrange type; ordinal type identifier = type identifier ; A.2.7.4 Pointer Types pointer type = "POINTER", "TO", bound type ; bound type = type ; A.2.7.5 Procedure Types procedure type = proper procedure type | function procedure type ; proper procedure type = "PROCEDURE", [ formal parameter type list ] ; function procedure type = "PROCEDURE", formal parameter type list , function result ; function result = ":", type identifier ; formal parameter type list = "(", [ formal parameter type, { ",", formal parameter type } ], ")" ; formal parameter type = variable formal type | value formal type ; variable formal type = "VAR", formal type ; value formal type = formal type ; formal type = { "ARRAY", "OF" }, type identifier ; A.2.7.6 Array Types array type = "ARRAY", index type, { ",", index type } , "OF", component type ; index type = ordinal type ; component type = type ; A.2.7.7 Record Types record type = "RECORD", [ field list ], "END" ; field list = fields, { ";", fields } ; fields = fixed fields | variant fields ; fixed fields = identifier list, ":", type ; variant fields = "CASE", [ tag identifier ], ":", tag type, "OF", variant, { "|", variant }, [ "ELSE", field list ], "END" ; tag identifier = identifier ; tag type = ordinal type identifier ; variant = [ case label list, ":", field list ] ; case label list = case label, { ",", case label } ; case label = constant expression, [ "..", constant expression ] ; A.2.8 Procedure Declarations procedure declaration = proper procedure declaration | function procedure declaration ; A.2.8.1 Proper Procedure Declarations proper procedure declaration = proper procedure heading, ";", ("FORWARD" | proper procedure block, procedure identifier) ; procedure identifier = identifier ; A.2.8.2 Proper Procedure Headings proper procedure heading = "PROCEDURE", procedure identifier, [ formal parameter list ] ; formal parameter list = "(", [ formal parameter, { ";", formal parameter } ], ")" ; A.2.8.3 Proper Procedure Block proper procedure block = declarations, [ "BEGIN", statement sequence ], "END" ; A.2.8.4 Function Procedure Declarations function procedure declaration = function procedure heading, ";", ("FORWARD" | function procedure block, procedure identifier) ; A.2.8.5 Function Procedure Headings function procedure heading = "PROCEDURE", procedure identifier, formal parameter list, function result ; A.2.8.6 Function Procedure Block function procedure block = declarations, "BEGIN", statement sequence , "END" ; +++++ Note: this may be a typographical error. Wirth had function procedure block = declarations, [ "BEGIN", statement sequence ], "END" ; +++++ however, a function procedure MUST have a RETURN statement. A.2.8.7 Parameters formal parameter = value parameter specification | variable parameter specification ; value parameter specification = identifier list, ":", formal type ; variable parameter specification = "VAR", identifier list, ":", formal type ; A.2.9 Module Declarations module declaration = "MODULE", module identifier, [ protection ], ";", { import lists }, [ export list ], module block, module identifier, "." ; +++++ Note this may be a typographical error. All that is needed is module declaration = "MODULE", module identifier, [ protection ], ";", import lists , [ export list ], module block, module identifier, "." ; +++++ the {} is already present in the production for import lists in A.1.6 -- uucp: uunet!m2xenix!puddle!5!494!4.101!Pat.Terry Internet: Pat.Terry@p101.f4.n494.z5.fidonet.org