Recent

Author Topic: A question on Modula2 vs Free Pascal  (Read 17714 times)

PeterBB

  • Jr. Member
  • **
  • Posts: 62
Re: A question on Modula2 vs Free Pascal
« Reply #105 on: March 26, 2025, 01:14:37 pm »
Is there any legal way of getting the complete ISO Modula-2 (parts 1, 2 and 3) BNF definition without buying the ISO documents ? I mean, the BNF only.

Daniel

If you are still looking ...
https://gcc.gnu.org/onlinedocs/gm2/EBNF.html

Sadly, GCC Pascal (gpc) died around version 4 of GCC, but Modula 2 seems alive and well.

Cheers,
Peter


Thaddy

  • Hero Member
  • *****
  • Posts: 16781
  • Ceterum censeo Trump esse delendam
Re: A question on Modula2 vs Free Pascal
« Reply #106 on: March 26, 2025, 01:22:47 pm »
Peter and dtoffe: a basic one
Code: [Select]
<program> ::= "MODULE" <identifier> ";"
              [ "IMPORT" <import-list> ";" ]
              <block>
              <identifier> "." .

<import-list> ::= <identifier> { "," <identifier> }

<block> ::= { <declaration> ";" }
            "BEGIN"
            { <statement> ";" }
            "END" .

<declaration> ::= <constant-declaration>
                | <type-declaration>
                | <variable-declaration>
                | <procedure-declaration>
                | <module-declaration>

<constant-declaration> ::= "CONST" { <identifier> "=" <constant> ";" }

<type-declaration> ::= "TYPE" { <identifier> "=" <type> ";" }

<variable-declaration> ::= "VAR" { <identifier-list> ":" <type> ";" }

<procedure-declaration> ::= "PROCEDURE" <identifier> [ "(" <formal-parameters> ")" ] ";"
                            <block> <identifier> .

<module-declaration> ::= "MODULE" <identifier> [ ";" <import-list> ] <block> <identifier> .

<formal-parameters> ::= [ "VAR" ] <identifier-list> ":" <type>
                        { ";" [ "VAR" ] <identifier-list> ":" <type> }

<type> ::= <simple-type> | <array-type> | <record-type> | <pointer-type> | <procedure-type>

<simple-type> ::= <identifier> | "INTEGER" | "BOOLEAN" | "CHAR" | "REAL" | enumeration | subrange

<array-type> ::= "ARRAY" <index-range> "OF" <type>

<record-type> ::= "RECORD" { <identifier-list> ":" <type> ";" } "END"

<pointer-type> ::= "POINTER" "TO" <type>

<procedure-type> ::= "PROCEDURE" [ "(" [ <formal-parameters> ] ")" ]

<statement> ::= <assignment>
              | <procedure-call>
              | <if-statement>
              | <case-statement>
              | <while-statement>
              | <repeat-statement>
              | <for-statement>
              | <loop-statement>
              | <exit-statement>
              | <return-statement>
              | <with-statement>

<assignment> ::= <designator> ":=" <expression>

<procedure-call> ::= <designator> [ "(" <actual-parameters> ")" ]

<if-statement> ::= "IF" <expression> "THEN" <statement-sequence>
                   { "ELSIF" <expression> "THEN" <statement-sequence> }
                   [ "ELSE" <statement-sequence> ]
                   "END"

<case-statement> ::= "CASE" <expression> "OF"
                     { <case-label> ":" <statement-sequence> "|" }
                     [ "ELSE" <statement-sequence> ]
                     "END"

<while-statement> ::= "WHILE" <expression> "DO" <statement-sequence> "END"

<repeat-statement> ::= "REPEAT" <statement-sequence> "UNTIL" <expression>

<for-statement> ::= "FOR" <identifier> ":=" <expression> "TO" <expression> [ "BY" <constant> ] "DO"
                    <statement-sequence> "END"

<loop-statement> ::= "LOOP" <statement-sequence> "END"

<exit-statement> ::= "EXIT"

<return-statement> ::= "RETURN" [ <expression> ]

<with-statement> ::= "WITH" <designator> "DO" <statement-sequence> "END"

<expression> ::= <simple-expression> [ <relation> <simple-expression> ]

<relation> ::= "=" | "#" | "<" | "<=" | ">" | ">=" | "IN"

<simple-expression> ::= [ "+" | "-" ] <term> { <add-op> <term> }

<term> ::= <factor> { <mul-op> <factor> }

<factor> ::= <number> | <string> | <designator> | "NIL" | "(" <expression> ")" | "NOT" <factor>

<designator> ::= <identifier> { "." <identifier> | "[" <expression-list> "]" | "^" }

<actual-parameters> ::= <expression> { "," <expression> }

<statement-sequence> ::= { <statement> ";" }
It is pure BNR. It has no correction recovery for corner cases.
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

 

TinyPortal © 2005-2018