-
Notifications
You must be signed in to change notification settings - Fork 3
/
van_bnf.js
125 lines (94 loc) · 1.67 KB
/
van_bnf.js
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
/***
1. van 类bnf部分语法
Program=States;
State=Expr State
| Assign State
| If State
| While State
| For State
| Fundef States
| Up State
| Continue State
| Break State
| Return State
| Classdef States
| Field State
| Print State
;
Expr=Identifi
| out Identifi
| Number
| Null
| True
| False
| Self
| Super
| String
| Map
| List
| FuncExpr
| ClassExpr
| (Expr)
| !Expr
| -Expr
| ~Expr
| new Expr
| Expr(ArgumentsExpr)
| Expr.Identifi
| Expr[Expr]
| Expr++
| Expr--
| Expr+Expr
| Expr-Expr
| Expr*Expr
| Expr/Expr
| Expr%Expr
| Expr>Expr
| Expr>=Expr
| Expr<Expr
| Expr<=Expr
| Expr==Expr
| Expr!=Expr
| Expr&&Expr
| Expr||Expr
| Expr<<Expr
| Expr>>Expr
| Expr&Expr
| Expr|Expr
| Expr?Expr:Expr
| Expr,Expr
;
Identifi="[_a-zA-Z][_a-zA-Z0-9]*";
Lital=Number
|String
|true
|false
|null
|Array
|Object
|FunctionExpr
|ClassExpr
;
Number=[-{0}.][1-9][0-9]*;
String=" " " .* " " ";
Array="["
Expr,Expr,...
"]";
Object={
Identifi : Expr,...
};
FunctionExpr=def (ArgumentsDef){ State }
ClassExpr=class (Expr){ [Field|Fundef] }
LeftExpr=Identifi|Expr.Identifi|Expr[Expr];
Assign=LeftExpr,LeftExpr,...=Expr,Expr,...;
If= if ( Expr ){ States } [else if( Expr ){ States }] [ else{ States } ];
While= while( Expr ){ State };
For= for ( Identifi in Expr ){ States };
Fundef=def Identifi( ArgumentsDef ){ States };
Classdef= class Identifi(Expr){ [Field|Fundef] };
Up= up [Identifi]*;
Field= field [Identifi]*;
Print= print [Expr]*;
ArgumentsExpr=[Expr]*;
ArgumentsDef=[[out] Identifi]*;
****/