summaryrefslogtreecommitdiff
path: root/old/minipascal.ebnf
blob: e0acf4a70b6d3b70633af317ca36e347da0451e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
     __________________________________________________________________

  Syntax of Mini-Pascal (Welsh & McKeag, 1980)
     __________________________________________________________________

   Syntax in recursive descent order
     __________________________________________________________________

   <program> ::= program <identifier> ; <block> .

   <block> ::= <variable declaration part>
   <procedure declaration part>
   <statement part>
     __________________________________________________________________

   <variable declaration part> ::= <empty> |
   var <variable declaration> ;
       { <variable declaration> ; }

   <variable declaration> ::= <identifier > { , <identifier> } : <type>

   <type> ::= <simple type> | <array type>

   <array type> ::= array [ <index range> ] of <simple type>

   <index range> ::= <integer constant> .. <integer constant>

   <simple type> ::= <type identifier>

   <type identifier> ::= <identifier>
     __________________________________________________________________

   <procedure declaration part> ::= { <procedure declaration> ; }

   <procedure declaration> ::= procedure <identifier> ; <block>
     __________________________________________________________________

   <statement part> ::= <compound statement>

   <compound statement> ::= begin <statement>{ ; <statement> } end

   <statement> ::= <simple statement> | <structured statement>
     __________________________________________________________________

   <simple statement> ::= <assignment statement> | <procedure statement> |
   <read statement> | <write statement>

   <assignment statement> ::= <variable> := <expression>

   <procedure statement> ::= <procedure identifier>

   <procedure identifier> ::= <identifier>

   <read statement> ::= read ( <input variable> { , <input variable> } )

   <input variable> ::= <variable>

   <write statement> ::= write ( <output value> { , <output value> } )

   <output value> ::= <expression>
     __________________________________________________________________

   <structured statement> ::= <compound statement> | <if statement> |
   <while statement>

   <if statement> ::= if <expression> then <statement> |
   if <expression> then <statement> else <statement>

   <while statement> ::= while <expression> do <statement>
     __________________________________________________________________

   <expression> ::= <simple expression> |
   <simple expression> <relational operator> <simple expression>

   <simple expression> ::= <sign> <term> { <adding operator> <term> }

   <term> ::= <factor> { <multiplying operator> <factor> }

   <factor> ::= <variable> | <constant> | ( <expression> ) | not <factor>
     __________________________________________________________________

   <relational operator> ::= = | <> | < | <= | >= | >

   <sign> ::= + | - | <empty>

   <adding operator> ::= + | - | or

   <multiplying operator> ::= * | div | and
     __________________________________________________________________

   <variable> ::= <entire variable> | <indexed variable>

   <indexed variable> ::= <array variable> [ <expression> ]

   <array variable> ::= <entire variable>

   <entire variable> ::= <variable identifier>

   <variable identifier> ::= <identifier>
     __________________________________________________________________

   Lexical grammar
     __________________________________________________________________

   <constant> ::= <integer constant> | <character constant> | <constant
   identifier>

   <constant identifier> ::= <identifier>

   <identifier> ::= <letter> { <letter or digit> }

   <letter or digit> ::= <letter> | <digit>

   <integer constant> ::= <digit> { <digit> }

   <character constant> ::= '< any character other than ' >'  |  ''''

   <letter> ::= a | b | c | d | e | f | g | h | i | j | k | l | m | n | o
   |
   p | q | r | s | t | u | v | w | x | y | z | A | B | C |
   D | E | F | G | H | I | J | K | L | M | N | O | P
   | Q | R | S | T | U | V | W | X | Y | Z

   <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

   <special symbol> ::= + | - | * | = | <> | < | > | <= | >= |
   ( | ) | [ | ] | := | . | , | ; | : | .. | div | or |
   and | not | if | then | else | of | while | do |
   begin | end | read | write | var | array |
   procedure | program

   <predefined identifier> ::= integer | Boolean | true | false
     __________________________________________________________________