-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAST.def
91 lines (66 loc) · 3.35 KB
/
AST.def
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
(*!m2pim*) (* Copyright (c) 2016 B.Kowarsch. All rights reserved. *)
DEFINITION MODULE AST;
(* AST for Modula-2 R10 Bootstrap Kernel *)
FROM AstQueue IMPORT AstQueueT;
FROM LexQueue IMPORT LexQueueT;
FROM AstNodeType IMPORT AstNodeTypeT;
TYPE AST; (* OPAQUE *)
TYPE AstT = AST; (* for unqualified use *)
(* Operations *)
PROCEDURE NewUnaryNode
( VAR ast : AST; nodeType : AstNodeTypeT; subnode : AST );
(* Allocates a new branch node of the given node type, stores the given
subnode in node and passes back node, or NIL on failure. *)
PROCEDURE NewBinaryNode
( VAR ast : AST; nodeType : AstNodeTypeT; subnode1, subnode2 : AST );
(* Allocates a new branch node of the given node type, stores the given
subnodes in node and passes back node, or NIL on failure. *)
PROCEDURE New3aryNode
( VAR ast : AST;
nodeType : AstNodeTypeT; subnode1, subnode2, subnode3 : AST );
(* Allocates a new branch node of the given node type, stores the given
subnodes in node and passes back node, or NIL on failure. *)
PROCEDURE New4aryNode
( VAR ast : AST;
nodeType : AstNodeTypeT; subnode1, subnode2, subnode3, subnode4 : AST );
(* Allocates a new branch node of the given node type, stores the given
subnodes in node and passes back node, or NIL on failure. *)
PROCEDURE New5aryNode
( VAR ast : AST;
nodeType : AstNodeTypeT;
subnode1, subnode2, subnode3, subnode4, subnode5 : AST );
(* Allocates a new branch node of the given node type, stores the given
subnodes in node and passes back node, or NIL on failure. *)
PROCEDURE NewListNode
( VAR ast : AST; nodeType : AstNodeTypeT; subnodes : AstQueueT );
(* Allocates a new branch node of the given node type, stores the subnodes of
* the given node queue in the node and passes back node, or NIL on failure. *)
PROCEDURE NewTerminalNode
( VAR ast : AST; nodeType : AstNodeTypeT; value : LexemeT );
(* Allocates a new terminal node of the given node type, stores the given
value in the node and passes back node, or NIL on failure. *)
PROCEDURE NewTerminalListNode
( VAR ast : AST; nodeType : AstNodeTypeT; values : LexQueueT );
(* Allocates a new terminal node of the given node type, stores the values of
the given value queue in the node and passes node, or NIL on failure. *)
PROCEDURE nodeType ( node : AST ) : AstNodeTypeT;
(* Returns the node type of node, or AST.Invalid if node is NIL. *)
PROCEDURE subnodeCount ( node : AST ) : CARDINAL;
(* Returns the number of subnodes or values of node. *)
PROCEDURE subnodeForIndex ( node : AST; index : CARDINAL ) : AST;
(* Returns the subnode of node with the given index or NIL if no subnode of
the given index is stored in node. *)
PROCEDURE valueForIndex ( node : AST; index : CARDINAL ) : LexemeT;
(* Returns the value stored at the given index in a terminal node,
* or NIL if the node does not store any value at the given index. *)
PROCEDURE value ( node : AST ) : LexemeT;
(* Calls function valueForIndex with an index of zero. *)
PROCEDURE replaceSubnode
( node : AST; atIndex : CARDINAL; withSubnode : AST ) : AST;
(* Replaces a subnode and returns the replaced node, or NIL on failure. *)
PROCEDURE replaceValue
( node : AST; atIndex : CARDINAL; withValue : LexemeT ) : LexemeT;
(* Replaces a subnode and returns the replaced value, or NIL on failure. *)
PROCEDURE Release ( VAR ast : AST );
(* Releases ast and passes back NIL if successful. *)
END AST.