-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbnf_eng.txt
119 lines (72 loc) · 3.09 KB
/
bnf_eng.txt
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
///////////////////////////////////////////////////////////////////////
Identifier [a-zA-Z_][a-zA-Z_0-9]*
Decimal -?[0-9]+
Hex "0x"[0-9a-fA-F]+
Integer {Decimal}|{Hex}
Float ({Decimal})?"."[0-9]+
String \"[^\"\n]*\"
Constant {Decimal}|{Hex}|{Float}|{String}
///////////////////////////////////////////////////////////////////////
BNF Syntax:
Program ::= Module ...
Module ::= ["module" Identifier] "{" [FuntionDef|ClassDef|StatementBlock]..."}"
VarDefStmt ::= [Modifiers]VarDefList ";"
VarDefList ::= VarDef ["," VarDef] ...
VarDef ::= Identifier ["=" Expression]
ConstDefStmt ::= [Modifiers] "const" ConstDefList ";"
ConstDefList ::= ConstDef ["," ConstDef] ...
ConstDef ::= Identifier "=" Expression
Modifiers ::= ["static"]("public"|"private"|"protected")
ClassDef ::= "class" Identifier ["("IdentList")"] "{" ClassBody "}" ";"
IdentList := Identifier ["," Identifier]...
ClassBody ::= [VarDefStmt|ConstDefStmt|FunctionDef] ...
FunctionDef ::= [Modifiers] "function" Identifier "(" IdentList ")"
Expression ::= RelationalExpr [LogicalOp RelationalExpr]...
RelationalExpr ::= AdditiveExpr [RelationalOp AdditiveExpr]...
AdditiveExpr ::= Term [AdditiveOp Term]...
Term ::= FactorExpr [MultiplicativeOp FactorExpr]...
FactorExpr ::= [UnaryOp] FactorExpr
| [UnaryOp] Factor
Factor ::= "(" Expression ")"
| FunctionCall
| Designator
| Constant
| Identifier
LogicalOp ::= "and"|"or"|"xor"
RelationalOp ::= ">"|"<"|"=="|"<>"|">="|"<="|"->"
AdditiveOp ::= "+"|"-"|"|"|"&"|"^"
MultiplicativeOp ::= "*"|"\"|"%"|"<<"|">>"|">>>"
UnaryOp ::= "+"|"-"|"!"|"not"
Designator ::= Expression ["[" Expression "]" | "." Identifier]
FunctionCall ::= Designator "(" ExpressionList ")"
ExpressionList ::= Expression ["," Expression]...
StatementBlock ::= Statement|StructStatement
StructStatement ::= "{" [Statement ...] "}"
Statement ::= VarDefStmt
| ConstDefStmt
| ConditionStatement
| LoopStatement
| TRYStatement
| AssignStatement
| FunctionCall ";"
| JumpStatement
ConditionStatement ::= IFStatement
IFStatement ::= "if" "(" Expression ")" StatementBlock ["else" StatementBlock]
LoopStatement ::= FORStatement1
|FORStatement2
|WHILEStatement
|REPEATStatement
FORStatement1 ::= "for" Designator "=" Expression "to" Expression ["step" Expression ] StatementBlock
FORStatement2 ::= "for" Designator "in" Expression StatementBlock
WHILEStatement ::= "while" "(" Expression ")" StatementBlock
REPEATStatement ::= "repeat" StatementBlock "until" Expression ";"
TRYStatement ::= "try" StatementBlock "catch" "(" Identifier ")" StatementBlock
AssignStatement ::= Designator "=" Expression ";"
JumpStatement ::= | RETURNStatement
| BREAKStatement
| CONTINUEStatement
| THROWStatement
RETURNStatement ::= "return" Expression ";"
BREAKStatement ::= "break" ";"
CONTINUEStatement ::= "continue" ";"
THROWStatement ::= "throw" Expression ";"