-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path分析表.txt
135 lines (78 loc) · 3.79 KB
/
分析表.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
select(<program>→<mainkey>(){<declarative_sequence><statement_sequence>}) = {main}
{Program.code = DeclarationSequence.code}
select(<declarative_sequence>→<declarative_statement><declarative_sequence>) = {int}
select(<declarative_sequence>→null) = {},if,while,for,scanf,printf,{,letter}
select(<declarative_statement>→<intkey><identifier_table>;) = {int}
select(<identifier_table>→<identifier><idts>) = {letter}
select(<idts>→,<identifier_table>) = {","}
select(<idts> -> null) = {;}
select(<statement_sequence>→<sentence><statement_sequence>) = {if,while,for,scanf,print,{,letter}
{StatementSequence.code = Sentence.code || StatementSequence.code}
select(<statement_sequence> → null) = {}}
{}
select(<sentence>→<if_sentence>) = {if}
{sentence.code = IfSentence.code}
select(<sentence>→<while_sentence>) = {while}
select(<sentence>→<for_sentence>) = {for}
{sentence.code = ForSentence.code}
select(<sentence>→<scanf_sentence>) = {scanf}
{sentence.code = ScanfSentence.code}
select(<sentence>→<printf_sentence>) = {printf}
{sentence.code = PrintfSentence.code}
select(<sentence>→<compound_statement>) = {{}
{sentence.code = CompoundStatement.code}
select(<sentence>→<assignment_statement>) = {id,unint,(}
{sentence.code = AssignmentStatement.code}
select(<if_sentence>→<ifkey> (
{expression.true = NewLabel() expression.false = NewLabel()}<expression>)
<compound_statement><elses>;
{IfSentence.code = expression.code || "expression.true :" || CompoundStatement.code ||
"expression.false :" || ElseSentence.code}
) = {if}
select(<elses>→<eleskey><compound_statement>) = {else}
select(<elses>→null) = {},for,while,if,scanf,printf,{,id}
select(<while_sentence>→<whilekey> (
{expression.true = NewLabel(); expression.false = WhileSentence.next}<expression>)
<compound_statement>
{WhileSentence.code = expression.code || "expression.true :" || CompoundStatement}
;) = {while}
select(<for_sentence>→<forkey> (<expression>;<expression>;<expression>) <compound_statement>;) = {for}
select(<compound_statement>→{<statement_sequence>}) = {{}
select(<assignment_statement>→<expression>;) = {id,number,(}
select(<expression>→<identifier><exps>) = {id}
select(<exps>→=<arithmetic_expression>) = {=}
select(<exps>→<rel>) = {+,-,*,/,>=,<=>,<,==,!=,;,)}
select(<rel>→<opt><relational_operator><arithmetic_expression>) = {+,-,*,/,>,<,>=,<=,==,!=}
select(<opt>→+<arithmetic_expression>) = {+}
select(<opt>→-<arithmetic_expression>) = {-}
select(<opt>→*<term>) = {*}
select(<opt>→/<term>) = {/}
select(<opt>→null) = {<,>,<=,>=,!=,==}
select(<rel>→null)={';',)}
--------------------------------------------------------------------------------------------------
select(<relational_operator>→>)={>}
select(<relational_operator>→<)={<}
select(<relational_operator>→>=)={>=}
select(<relational_operator>→<=)={<=}
select(<relational_operator>→==)={==}
select(<relational_operator>→!=)={!=}
//select(<relational_operator>→><eq>)={>}
//select(<relational_operator>→<<eq>)={<}
//select(<relational_operator>→=<eq>)={=}
//select(<relational_operator>→!<eq>)={!}
//select(<eq>→=)={=}
//select(<eq>→null)={id,unint,(}
select(<arithmetic_expression>→<term><oparit>)={id,number,(}
select(<oparit>→+<arithmetic_expression>)={+}
select(<oparit>→-<arithmetic_expression>)={-}
select(<oparit>→null)={<,>,<=,>=,!=,==,),;}
select(<term>→<factor><opterm>)={id,number,(}
select(<opterm>→*<term>) = {*}
select(<opterm>→/<term>) = {/}
select(<opterm>→null) = {+,-,<,>,=,!,;,)}
select(<factor>→<identifier>) = {id}
select(<factor>→<unint>)={number}
select(<factor>→(<arithmetic_expression>)) = {(}
------------------------------------
select(<scanf_sentence>→<scanfkey>(id);)={scanf}
select(<printf_sentence>→<printfkey>(id);)={printf}