-
Notifications
You must be signed in to change notification settings - Fork 1
/
AST.def
69 lines (45 loc) · 2.3 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
(*!m2r10*) (* Copyright (c) 2015 B.Kowarsch. All rights reserved. *)
DEFINITION MODULE AST;
(* AST for Modula-2 R10 Core Compiler *)
IMPORT AstQueue, LexQueue;
TYPE AST = OPAQUE;
(* Constructors *)
PROCEDURE NewNode
( VAR ast : AST; nodeType : AstNodeType; subnodes : ARGLIST OF AST );
(* Allocates a new branch node of the given node type, stores the subnodes of
the argument list in the node and passes back node, or NIL on failure. *)
PROCEDURE NewListNode
( VAR ast : AST; nodeType : AstNodeType; subnodes : AstQueue );
(* 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 : AstNodeType; value : Lexeme );
(* 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 : AstNodeType; values : LexQueue );
(* 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. *)
(* Destructor *)
PROCEDURE Release ( VAR ast : AST );
(* Releases ast and passes back NIL if successful. *)
(* Operations *)
PROCEDURE nodeType ( node : AST ) : AstNodeType;
(* 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 ) : Lexeme;
(* 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 ) : Lexeme;
(* 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 : Lexeme ) : Lexeme;
(* Replaces a subnode and returns the replaced value, or NIL on failure. *)
END AST.