-
Notifications
You must be signed in to change notification settings - Fork 71
/
grammar.txt
executable file
·78 lines (59 loc) · 2.39 KB
/
grammar.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
语法分析器所用到的文法。
notice:首字母大写的除了ID外为非终结符,剩下的为终结符,ID表示标识符。
''''''''''''''''''''''''''''''''''''
'句子
''''''''''''''''''''''''''''''''''''
Sentence --> Include | Statement | Assignment | Control | Expression | Constant | FunctionStatement | FunctionCall //克林闭包
''''''''''''''''''''''''''''''''''''
'导入语句include
''''''''''''''''''''''''''''''''''''
Include --> #include < ID > | #include "ID"
''''''''''''''''''''''''''''''''''''
'声明语句
''''''''''''''''''''''''''''''''''''
Statement --> Type ID; | Type ID[ Constant ]; | Type ID[ Constant ] = { ConstantList };
Type --> int | float
ConstantList --> ∑ | Constant ConstantRest
ConstantRest --> ∑ | ,Constant | ConstantRest
ConstantRest --> (,Constant)*
''''''''''''''''''''''''''''''''''''
'赋值语句
''''''''''''''''''''''''''''''''''''
Assignment --> ID = Expression;
''''''''''''''''''''''''''''''''''''
'控制语句
''''''''''''''''''''''''''''''''''''
Control --> IfControl | WhileControl | ForControl
IfElseControl --> IfControl ElseControl
IfControl --> if( Expression ){ Sentence }
ElseControl --> ∑ | else{ Sentence }
WhileControl --> while( Expression ){ Sentence }
ForControl --> for( Assignment; Expression; Expression ){ Sentence }
''''''''''''''''''''''''''''''''''''
'表达式
''''''''''''''''''''''''''''''''''''
Expression --> ( Expression ) | Expression Operator Expression | SingleOperator Expression | ArrayIndex | Constant
ArrayIndex --> ID[ Constant ]
SingleOperator --> ! | ++ | --
Operate --> + | - | * | / | ++ | -- | > | < | >= | <= | &
''''''''''''''''''''''''''''''''''''
'常量
''''''''''''''''''''''''''''''''''''
Constant --> Num | String
Num --> [0-9] | [1-9][0-9]+ //正则表达式表示
String --> [a-zA-Z0-9\n%:,.]+ //正则表达式表示
''''''''''''''''''''''''''''''''''''
'函数声明、调用
''''''''''''''''''''''''''''''''''''
FunctionStatement --> Type FunctionName( StateParameterList ){ Sentence }
StateParameterList --> ∑ | Parameter ParameterRest
Parameter --> Type ID
ParameterRest --> ∑ | ,Parameter | ParameterRest
Type --> int | float | char | double
FunctionCall --> ID( CallParameterList );
CallParameterList --> ∑ | ID ParameterRest
ParameterRest --> ∑ | ,ID | ParameterRest
''''''''''''''''''''''''''''''''''''
'return语句
''''''''''''''''''''''''''''''''''''
Return --> return Expresstion;