source: liacs/coco/assignment3/Node.h@ 195

Last change on this file since 195 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 4.5 KB
RevLine 
[2]1/*
2 * Node.h
3 *
4 * This file contains the declaration of the "Node" structure. It is part of
5 * the assignment for the Compiler Construction course at the Leiden Institute
6 * of Advanced Computer Science (LIACS), Leiden University.
7 *
8 * Note: when a Node is deleted, is does _not_ delete its children. Also the
9 * Symbol of a Node_Symbol object is preserved.
10 */
11
12#ifndef _NODE_H_
13#define _NODE_H_
14
15#include <cstdlib>
16#include <cstdio>
17#include "types.h"
18#include "Symbol.h"
19
20// ----------------------------------------------------------------------------
21// N O D E ( B A S E )
22// ----------------------------------------------------------------------------
23
24class Node {
25
26 public:
27
28 // constructor
29 Node (void);
30
31 // destructor
32 virtual ~Node (void);
33
34 // gets the node type
35 NodeType GetNodeType (void);
36
37 // sets the node type
38 void SetNodeType (NodeType nodeType);
39
40 // gets the return type
41 ReturnType GetReturnType (void);
42
43 // sets the return type
44 void SetReturnType (ReturnType returnType);
45
46 // dumps the node data
47 virtual void Dump (FILE * file, int indent);
48
49 // (empty) virtuals
50 virtual Node * GetChild (void);
51 virtual void SetChild (Node * node);
52 virtual Node * GetLeftChild (void);
53 virtual void SetLeftChild (Node * node);
54 virtual Node * GetRightChild (void);
55 virtual void SetRightChild (Node * node);
56
57 virtual int GetIntValue (void);
58 virtual void SetIntValue (int newvalue);
59 virtual float GetRealValue (void);
60 virtual void SetRealValue (float newvalue);
61 virtual Symbol * GetSymbol (void);
62 virtual void SetSymbol (Symbol * newsym);
63
64 private:
65
66 NodeType myNodeType;
67 ReturnType myReturnType;
68
69};
70
71
72
73// ----------------------------------------------------------------------------
74// N O D E U N A R Y
75// [ unary minus, "not x", etc.]
76// ----------------------------------------------------------------------------
77class Node_Unary: public Node {
78
79 public:
80
81 // constructor
82 Node_Unary (void);
83
84 // destructor
85 ~Node_Unary (void);
86
87 // gets the child
88 Node * GetChild (void);
89
90 // sets the child
91 void SetChild (Node * node);
92
93 // dumps the node data
94 void Dump(FILE * file, int indent);
95
96 private:
97
98 Node * Child;
99
100};
101
102
103
104// ----------------------------------------------------------------------------
105// N O D E B I N A R Y
106// ["while L do R", "A ; B", "4 * 3", etc.]
107// ----------------------------------------------------------------------------
108class Node_Binary: public Node {
109
110 public:
111
112 // constructor
113 Node_Binary (void);
114
115 // destructor
116 ~Node_Binary (void);
117
118 // gets the left child
119 Node * GetLeftChild (void);
120
121 // sets the left child
122 void SetLeftChild (Node * node);
123
124 // gets the right child
125 Node * GetRightChild (void);
126
127 // sets the right child
128 void SetRightChild (Node * node);
129
130 // dumps the node data
131 void Dump (FILE * file, int indent);
132
133 private:
134
135 Node * leftChild;
136 Node * rightChild;
137
138};
139
140
141
142// ----------------------------------------------------------------------------
143// N O D E I N T E G E R
144// ----------------------------------------------------------------------------
145class Node_Integer: public Node {
146
147 public:
148
149 // gets the integer value
150 int GetIntValue (void);
151
152 // sets the integer value
153 void SetIntValue (int value);
154
155 // dumps the node data
156 void Dump (FILE * file, int indent);
157
158 private:
159
160 int myValue;
161
162};
163
164
165
166// ----------------------------------------------------------------------------
167// N O D E R E A L
168// ----------------------------------------------------------------------------
169class Node_Real: public Node {
170
171 public:
172
173 // gets the real value
174 float GetRealValue (void);
175
176 // sets the real value
177 void SetRealValue (float value);
178
179 // dumps the node data
180 void Dump (FILE * file, int indent);
181
182 private:
183
184 float myValue;
185
186};
187
188
189
190// ----------------------------------------------------------------------------
191// N O D E S Y M B O L
192// ----------------------------------------------------------------------------
193// symbol leaf
194class Node_Symbol: public Node {
195
196 public:
197
198 // gets the symbol pointer
199 Symbol * GetSymbol (void);
200
201 // sets the symbol pointer
202 void SetSymbol (Symbol * symbol);
203
204 // dumps the node data
205 void Dump (FILE * file, int indent);
206
207 private:
208
209 Symbol * mySymbol;
210
211};
212
213#endif
214
Note: See TracBrowser for help on using the repository browser.