-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrammar.ebnf
40 lines (40 loc) · 1.95 KB
/
grammar.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
37
38
39
40
statement ::= if_statement
| while_statement
| next_statement
| break_statement
| let_statement
| assign_statement
| print_statement
| err_statement
| scan_statement
| function_declaration
| return_statement
| expr;
if_statement ::= "if" expr block_statement
{ "elif" expr block_statement }
[ "else" block_statement ];
while_statement ::= "while" expr block_statement;
next_statement ::= "next";
break_statement ::= "break";
let_statement ::= "let" IDENT "=" expr;
assign_statement ::= IDENT "=" expr;
print_statement ::= "print" expr;
err_statement ::= "err" expr;
scan_statement ::= "scan" IDENT;
function_declaration ::= "def" IDENT "(" { IDENT "," } [ IDENT ] ")" block_statement;
return_statement ::= "return" expr;
block_statement ::= "{" eol { statement eol } "}" | "{" statement "}";
expr ::= or_expr;
or_expr ::= and_expr { "or" and_expr };
and_expr ::= eq_expr { "and" eq_expr };
eq_expr ::= comp_expr { ("==" | "!=") comp_expr };
comp_expr ::= concat_expr { (">" | "<" | ">=" | "<=") concat_expr };
concat_expr ::= add_expr { "&" add_expr };
add_expr ::= mul_expr { ("+" | "-") mul_expr };
mul_expr ::= unary_expr { ("*" | "/") unary_expr };
unary_expr ::= ("+" | "-" | "!" | "&") unary_expr | no_op_expr;
no_op_expr ::= literal | group | function_call | IDENT;
literal ::= "true" | "false" | DIGITS | DIGITS "." DIGITS | STRING;
function_call ::= IDENT "(" { IDENT "," } [ IDENT ] ")";
group ::= "(" expr ")";
eol ::= "\r\n" | "\n";