/
grammar_wp.bnf
38 lines (32 loc) · 1.7 KB
/
grammar_wp.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
<Program> ::= ( <Prog_list> )
<Prog_list> ::= <Meth_or_fun> | <Program> <Meth_or_fun>
<Meth_or_fun> ::= <Method> | <Function>
<Function> ::= ( fun ( <Arglist> ) <Instr_list> )
<Arglist> ::= id | id <Arglist>
<Method> ::= ( method . number ( <Arglist> ) <Instr_list> )
<Instr_list> ::= <Instr> | ( <Instr_list_np> )
<Instr_list_np> ::= <Instr> | <Instr> <Instr_list_np>
<Instr> ::= <Conditional> | <While_block> | <Call> | ( return <Expr> )
<Conditional> ::= ( if <Cond> <instr_list> <instr_list> ) | ( if <Cond> <instr_list> )
<While_block> ::= ( while <Cond> <Instr_list> )
<call> ::= <User_call> | <Method_call> | <Builtin_call>
<Builtin_call> ::= <Assignment> | <Read_call> | <Write_call> | <Arithmetic_call>
<Assignment> ::= ( set id <Expr> ) | ( set id . number <Expr> ) | ( set this . number <Expr> )
<Read_call> ::= ( read )
<Write_call> ::= ( 'write' <Expr> )
<Arithmetic_call> ::= <Binary> | <Unary>
<Binary> ::= ( <Bin_id> <Expr> <Expr> )
<Unary> ::= ( <Un_id> <Expr> )
<User_call> ::= ( id <Expr_list_np> ) | ( id )
<Expr_list_np> ::= <Expr> | <Expr> <Expr_list_np>
<Method_call> ::= ( id . id <Expr_list_np> ) | ( id . id )
<Method_call> ::= ( super . id <Expr_list_np> ) | ( super . id )
<Method_call> ::= ( this . id <Expr_list_np> ) | ( this . id )
<Expr> ::= <Instr> | number | null | true | false | this | id | id . number | this . number
<Cond> ::= <Rel> | ( <Log_bin_op> <Cond> <Cond> ) | ( <Log_un_op> <Cond> <Cond> )
<Rel> ::= ( <Rel_op> <Expr> <Expr> )
<Rel_op> ::= <= | >= | > | < | =
<Log_bin_op> ::= and | or
<Log_un_op> ::= !
<Bin_id> ::= + | - | * | / | %
<Un_id> ::= neg