[comp.lang.modula2] 02/Re: m2 grammar

Pat.Terry@p101.f4.n494.z5.fidonet.org (Pat Terry) (04/05/90)

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 D102, but not
quoted in the appendix 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 is 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