-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmini.ebnf
36 lines (36 loc) · 1.57 KB
/
mini.ebnf
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
program -> types declarations functions
types -> {type-declaration}∗
type-declaration -> 'struct' id '{' nested-decl '}' ';'
nested-decl -> decl ';' { decl ';'}∗
decl -> 'type' id
type -> 'int' | 'bool' | 'struct' id | 'int_array'
declarations -> {declaration}∗
declaration -> 'type' id-list ';'
id-list -> id {',' id}∗
functions -> {function}∗
function -> 'fun' id parameters return-type '{' declarations statement-list '}'
parameters -> '(' {decl { ',' decl}∗}opt ')'
return-type -> type | 'void'
statement -> block | assignment | print | conditional | loop | delete | ret | invocation
block -> { statement-list }
statement-list -> {statement}∗
assignment -> lvalue '=' { expression | 'read' } ';'
print -> 'print' expression { 'endl' }opt ;
conditional -> if '(' expression ')' block { 'else' block }opt
loop -> 'while' '(' expression ')' block
delete -> 'delete' expression ;
ret -> 'return' {expression}opt ';'
invocation -> id arguments ';'
lvalue -> id { '.' id}∗
expression -> boolterm { '||' boolterm}∗
boolterm -> eqterm { '&&' eqterm}∗
eqterm -> relterm {{ '==' | '!=' } relterm}∗
relterm -> simple {{ '<' | '>' | '<=' | '>=' } simple}∗
simple -> term {{ '+' | '−' } term}∗
term -> unary {{ '∗' | '/' } unary}∗
unary -> { '!' | '−' }∗ selector
selector -> factor {{'.' id} | '[' number ']'}∗
factor -> '(' expression ')' | id {arguments}opt | number | 'true' |
| 'false' | 'new' id | 'null' | 'new' 'int_array' '[' number ']' |
arguments -> '(' {expression { ',' expression}∗}opt ')'
number -> {'0' | '1' | ... | '9'}{ '0' | '1' | ... | '9'}∗