apt.nodes
2.71 KB
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Basic types.
%
%
% Stream coordinates.
position(Line : integer, Col : integer).
range(Begin : position, End : position).
%
% Identifiers.
idList.
[Name:id, Next:idList] >> idList.
[] >> idList.
id(Name : string).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Type expressions.
%
type(Storage).
simpleType >> type.
numType >> simpleType.
intType >> numType(storage = 4).
realType >> numType(storage = 4).
boolType >> simpleType(storage = 1).
voidType >> simpleType(storage = 1).
mapType(Domain : typeList, Range : typeList) >> type.
arrayType(Size : int, ElemType : type) >> type.
classType(Decls : declList) >> type.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Expressions.
%
exp(Value, Type : type) << ReadOnly : boolean >> .
expList >> exp.
expPair(Head : exp, Tail : expList) >> expList.
expVoid >> expList.
valueExp << ReadOnly = true >> exp.
opExp(Op : op) >> valueExp.
unExp(Arg : exp) >> opExp.
binExp(Arg1 : exp, Arg2 : exp) >> opExp.
litExp >> valueExp.
intLit(Value : int) >> litExp.
realLit(Value : real) >> litExp.
boolLit(Value : bool) >> litExp.
arrayLit(NElem : int, Value : expList) >> litExp.
mapLit(Formals : declList, Body : stat) >> litExp.
classLit(Formals : declList, Body : stat) >> litExp.
% mapExp() includes array expressions
mapExp(Fun : exp, Args : expList) >> exp.
idExp(Id : id) >> exp.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Statements.
%
stat << Where : lc >> .
statList >> stat.
statPair(Head : stat, Tail : statList) >> statList.
statVoid >> statList.
declStat(Decl : decl) >> stat.
operStat >> stat.
assignStat(LValue : exp, RValue : exp) >> operStat.
funCallStat(Fun : exp, Args : expList) >> operStat.
controlStat >> stat.
condStat(Clauses : clauses) >> controlStat.
whileStat(Clauses : clauses) >> controlStat.
returnStat(Value : exp) >> controlStat.
%
% Clauses for conditional statements.
clauses << Where : lc >> .
condClause(Cond : exp, Body : stat, Next : clauses) >> clauses.
elseClause(Body : stat) >> clauses.
voidClause >> clauses.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Declarations.
%
declList.
declPair(Head : decl, Tail : declList) >> declList.
declVoid >> declList.
decl(Names : idList, Type : type).
constDecl(Value : exp) >> decl.
varDecl >> decl.
initVarDecl(Value : exp) >> varDecl.
typeDecl >> decl.
formalList.
formalPair(Head : formal, Tail : formalList) >> formalList.
formalVoid >> formalList.
formal(Names : idList, Type : Type).