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 2 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 ----------------------------- Part 2 starts here ------------------------- A.3 Statements statement = empty statement | assignment statement | procedure call | return statement | with statement | if statement | case statement | while statement | repeat statement | loop statement | exit statement | for statement ; A.3.1 Statement Sequences statement sequence = statement, { ";", statement } ; A.3.2 Empty Statements empty statement = ; A.3.3 Assignment Statements assignment statement = variable designator, assignment operator, expression ; assignment operator =":=" ; A.3.4 Procedure Calls procedure call = procedure designator, [ actual parameters ] ; procedure designator = value designator ; actual parameters = "(", [ actual parameter list ], ")" ; actual parameter list = actual parameter, { ",", actual parameter } ; actual parameter = variable designator | expression | type parameter ; type parameter = type identifier ; A.3.5 Return Statements return statement = simple return statement | function return statement ; A.3.5.1 Simple Return Statements simple return statement = "RETURN" ; A.3.5.2 Function Return Statements function return statement = "RETURN", expression ; A.3.6 With Statements with statement = "WITH", record designator, "DO", statement sequence, "END" ; record designator = variable designator | value designator ; A.3.7 If Statements if statement = guarded statements, [ "ELSE", statement sequence ], "END" ; guarded statements = "IF", Boolean expression, "THEN", statement sequence, { "ELSIF", Boolean expression, "THEN", statement sequence } ; Boolean expression = expression ; A.3.8 Case Statements case statement = "CASE", case selector, "OF", case, { " | ", case }, [ "ELSE", statement sequence ], "END" ; case selector = ordinal expression ; case = [ case label list, ":", statement sequence ] ; +++++ Note that the productions case label list = case label, { ",", case label } ; case label = constant expression, [ "..", constant expression ] ; +++++ have already been given in A.2.7.7 A.3.9 While statements while statement = "WHILE", Boolean expression, "DO", statement sequence, "END" ; A.3.10 Repeat Statements repeat statement = "REPEAT", statement sequence, "UNTIL", Boolean expression ; A.3.11 Loop Statements loop statement = "LOOP", statement sequence, "END" ; A.3.12 Exit Statements exit statement = "EXIT" ; A.3.13 For Statements for statement = "FOR", control variable, assignment operator, initial value, "TO", final value, [ "BY", step value], "DO", statement sequence, "END" ; control variable = identifier ; initial value = ordinal expression ; final value = ordinal expression ; step value = constant expression ; A.4 Variable Designators variable designator = entire designator | indexed designator | selected designator | dereferenced designator ; A.4.1 Entire Designators entire designator = qualified identifier ; A.4.2 Indexed Designators indexed designator = array designator, "[", index expression, { ",", index expression }, "]" ; array designator = variable designator ; index expression = ordinal expression ; ordinal expression = expression ; A.4.3 Selected Designators selected designator = record designator, ".", field identifier ; record designator = variable designator ; field identifier = identifier ; A.4.4 Dereferenced Designators dereferenced designator = pointer designator, dereferencing operator ; pointer designator = variable designator ; dereferencing operator = "^"; A.5 Expressions expression = simple expression, [ relational operator, simple expression ] ; simple expression = [ sign ], term, { term operator, term } ; term = factor, { factor operator, factor } ; factor = "(", expression, ")" | not operator, factor | function call | value constructor | constant literal ; A.5.1 Infix Expressions factor operator = "*" | "/" | "REM" | "DIV" | "MOD" | and operator ; and operator = "AND" | "&" ; term operator = "+" | "-" | "OR" ; relational operator = "=" | inequality operator | "<" | ">" | "<=" | ">=" | "IN" ; inequality operator= "<>" | "#" ; A.5.2 Prefix Expressions sign = [ "+" | "-" ] ; +++++ Note that all that is needed ia sign = "+" | "-" ; +++++ as the [] are already present in the production for simple expression not operator = "NOT" | "~" ; A.5.3 Value Designator value designator = entire value | indexed value | selected value | dereferenced value ; A.5.3.1 Entire Values entire value = qualified identifier ; A.5.3.2 Indexed Values indexed value = array value, "[", index expression, { ",", index expression }, "]" ; array value = value designator ; index expression = ordinal expression ; A.5.3.3 Selected Values selected value = record value, ".", field identifier ; record value = value designator ; A.5.3.4 Dereferenced Values dereferenced value = pointer value, dereferencing operator ; pointer value = value designator ; A.5.4 Function Call function call = function designator, "(", [ actual parameter list ], ")" ; function designator = value designator; A.5.5 Value Constructors +++++ Note: This represents an addition to the language (except for sets) value constructor = array constructor | record constructor | set constructor ; A.5.5.1 Array Constructor array constructor = type identifier, array definition ; +++++ Note: this might be better as array constructor = array type identifier, array definition ; array type identifier = type identifier ; array definition = "{", repeated element, { ",", repeated element }, "}" ; repeated element = element, [ "BY", repetition factor ] ; element = expression | array definition | record definition | set definition ; repetition factor = constant expression ; A.5.5.2 Record Constructors record constructor = type identifier, record definition; +++++ Note: this might be better as record constructor = record type identifier, record definition; record type identifier = type identifier ; record definition = "{", [ repeated element, {"," , repeated element } ], "}" ; field value = expression ; +++++ Note; this last production is presumably a typographical error. An earlier draft had record definition = "{", field value, {"," , field value }, "}" ; field value = expression ; A.5.5.3 Set Constructors set constructor = type identifier, set definition; +++++ Note: this might be better as set constructor = set type identifier, set definition; set type identifier = type identifier ; set definition = "{", [ member sequence]. "}" ; member sequence = member, { "," , member } ; member = singleton | interval; singleton = ordinal expression ; interval = ordinal expression, "..", ordinal expression ; A.5.6 Constant Literals constant literal = whole number literal | real literal | string literal | character literal ; A.5.6.1 String Literals string literal = single string, { catenate symbol, single string } ; +++++ Note: the "catenation" option is new to the language. single string = character string | string identifier ; string identifier = qualified identifier ; A.5.6.2 Character Literals character literal = quoted character | character number literal ; +++++ Note: These last sections are "incomplete" in that non-terminals are introduced that are not defined in appendix A of D102. This is because one is into the area of lexical/syntax analysis. The relevant productions are given in section 5 of D102, as follows: 5.6.2 Whole number literals whole number literal = decimal number | octal number | hexadecimal number ; decimal number = digit, { digit } ; digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; octal number = octal digit, { octal digit }, "B" ; octal digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ; hexadecimal number = digit, { hex digit }, "H"; digit = octal digit | "8" | "9" ; hex digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "A" | "B" | "C" | "D"| "E" | "F" ; 5.6.3 Real literals real literal = digit, { digit }, ".", { digit }, [ scale factor ] ; scale factor = "E", [ "+" | "-" ], digit, { digit} ; 5.6.4 String Literals string literal = "'", { national character - "'" }, "'" | '"', { national character - '"' }, '"'; 5.6.5 Character Literals quoted character = "'", national character - "'" , "'" | '"', national character - '"' , '"'; character number literal = octal digit, { octal digit }, "C" ; A.6 Qualified Identifiers qualified identifier = identifier, { ".", identifier } ; Some of the other productions of note given in section 5 of D106, but not quoted in the appendix (from which the rest of this was taken) are 5.3 Identifiers identifier = full identifier | portable identifier ; portable identifier = simple letter, { [low line], simple alphanumeric } ; low line = "_" ; full identifier = letter, { [low line], national alphanumeric } ; 5.5.2.5 Catenate symbol catenate symbol = normal catenate | alternative catenate ; normal catenate = "||" ; alternative catenate = "!!" ; +++++ Note: normal catenate will be unacceptable. The sequence || can already appear in "empty" case lists. 5.7 Letters and national characters letter = ? implementation defined alphabetic character ? national character = national alphanumeric | simple alphanumeric | ? implementation defined character ? ; national alphanumeric = letter | national numeric ; national numeric = ? implementation defined numeric character ? ; simple alphanumeric = simple letter | digit ; simple letter = "a".."z" | "A".."Z" ? ; -- uucp: uunet!m2xenix!puddle!5!494!4.101!Pat.Terry Internet: Pat.Terry@p101.f4.n494.z5.fidonet.org