-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.bnf
154 lines (110 loc) · 5 KB
/
project.bnf
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Programs:
<program> ::= program <identifier> <parameter list>
<top definations>?
is
<variable definations>?
begin
<statements>?
end
Declarations:
<top definations> ::= <top defination>
| <top definations> <top defination>
<top definaton> ::= <function defination>
| <type defination>
<function defination> ::= function <identifier> <parameter list>
<variable definations>?
<return type>?
is
<varaible definations>?
begin
<statements>?
end function <identifier>;
<return type> ::= return <identifier>;
<type defination> ::= <class definaton>
| <array defination>
<array defination> ::= type <identifier> is array of <number> <identifier>;
<class defination> ::= type <identifier> is class <extends>
<member definations>?
end class;
<member definations> ::= <member definaton>
| <member definations> <member defination>
<member defination> ::= <function defination>
| <varible defination>
<varible definations> ::= <varible defination>
| <varible definations> <varible defination>
<varible defination> ::= var <identifier> is <identifier>;
<parameter list> ::= (<parameters>?)
<parameters> ::= <identifier>
| <parameters>, <identifier>
Expressions:
<relation operator> ::= < | <= | == | != | > | >=
<expression> ::= <bool term>
| <expression> or <bool term>
<bool term> ::= <bool factor>
| <term> and <bool factor>
<bool fatcor> ::= <bool atom>
| !<bool factor>
<bool atom> ::= yes
| no
| <arith expression>
| <arith expression> <relation operator> <arith expression>
<arith expression> ::= <arith term>
| <arith expr> + <arith term>
| <arith expr> - <arith term>
<arith term> ::= <arith factor signed>
| <arith term> * <arith factor signed>
| <arith term> / <arith factor signed>
| <arith term> % <arith factor signed>
<arith factor signed> ::= <arith factor>
| + <arith factor signed>
| - <arith factor signed>
<arith factor> ::= <arith atom>
| <arith factor> . <identifier>
| <arith factor> . <identifier> <pass value list>
| <arith factor> [ <expression> ]
<arith atom> ::= <number>
| ( <expression> )
| <identifier> <pass value list>
| <identifier>
<pass value list> ::= ( <pass values>? )
<pass values> ::= <expression>
| <pass values> , <expression>
Blocks and Commands:
<statements> ::= <statement>
| <statements> <statement>
<statement> ::= <assign statement>
| <if statement>
| <while statement>
| <repeat statement>
| <foreach statement>
| <print statement>
| <return statement>
| <expression>?;
<assign statement> ::= <expression> = <expression>;
<if statement> ::= if <expression> then
<statements>?
<elif branches>?
<else branches>?
end if
<elif branches> ::= <elif branch>
| <elif branches> <elif branch>
<elif branch> ::= elif <statements>
<else branch> ::= else <statements>
<while statement> ::= while <expression> do
<statements>
end while
<repeat statement> ::= repeat
<statements>
until <expression> ;
<foreach statement> ::= foreach <identifier> in <expression> do
<statements>
end foreach
<return statement> ::= return <expression>;
<print statement> ::= print <expression>;
Tokens:
<number> ::= 0 | <non zero digit><digits>?
<digits> ::= <digit> | <digits> <digit>
<digit> ::= 0 | <non zero digit>
<non zero digit> ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<keyword> ::= program | function | return | type | var | is | begin | if | then | end | elif | else | while | do | repeat | until | foreach | print | of | array | class | extends | in | and | or | not | yes | no
<identifier> is string which match the regex '[_a-zA-Z][_a-zA-Z0-9]*'