-
Notifications
You must be signed in to change notification settings - Fork 1
/
tiger.txt
104 lines (78 loc) · 1.89 KB
/
tiger.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
## LL(1) grammer of tiger programming language
program -> exp
exps -> exp SEMICOLON exps
->
exp -> letexp
-> ifexp
-> whileexp
-> forexp
-> BREAK
-> binaryexp (parse by pratt parser)
binaryexp -> sub binaryexp_
-> binaryexp_
binaryexp_ -> item op_exp_
op_exp_ -> op item op_exp_
->
op -> ASSIGN
-> ADD
-> SUB
-> MUL
-> DIV
-> AND
-> OR
-> EQ
-> NEQ
-> LE
-> LT
-> GT
-> GE
item -> NIL
-> INT_LITERAL
-> STRING_LITERAL
-> IDENTIFIER identifier_suffix_
-> L_SMALL exps R_SMALL
identifier_suffix_ -> L_SMALL arglist R_SMALL
-> L_MID exp R_MID of_exp_
-> L_BIG fassignlist R_BIG
-> DOT IDENTIFIER identifier_suffix_
->
of_exp_ -> OF item
->
letexp -> LET decs IN exps END
ifexp -> IF exp THEN exp elseexp
elseexp -> ELSE exp
->
whileexp -> WHILE exp DO exp
forexp -> FOR IDENTIFIER ASSIGN exp TO exp DO exp
ofexp -> OF exp
->
fassignlist -> IDENTIFIER EQ exp fassignlist_
fassignlist_ -> COMMA IDENTIFIER EQ exp fassignlist_
->
arglist -> IDENTIFIER arglist_
arglist_ -> COMMA IDENTIFIER arglist_
->
decs -> dec decs
->
dec -> tydecs
-> vardec
-> funcdecs
tydecs -> tydec tydecs
->
tydec -> TYPE IDENTIFIER EQ ty
vardec -> VAR IDENTIFIER COLON IDENTIFIER ASSIGN exp
funcdecs -> funcdec funcdecs
funcdec -> FUNCTION IDENTIFIER L_SMALL tyfields R_SMALL funcdec_
funcdec_ -> EQ exp
-> COLON IDENTIFIER EQ exp
ty -> IDENTIFIER
-> ARRAY OF IDENTIFIER
-> L_BIG tyfields R_BIG
tyfields -> tyfield tyfields_
->
tyfields_ -> COMMA tyfield tyfields_
->
tyfield -> IDENTIFIER COLON IDENTIFIER
## changes on grammer
1. the body of for-exp, while-exp, if-then-exp might has value, and the exp itself has no value.
2. the procedure may has return value