source: liacs/coco/assignment2/SyntaxTree.h@ 357

Last change on this file since 357 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: 2.4 KB
RevLine 
[2]1/*
2 * SyntaxTree.h
3 *
4 * This file contains the declaration of the "Syntax Tree", an abstract
5 * data structure. It is part of the assignment for the Compiler Construction
6 * course at the Leiden Institute of Advanced Computer Science (LIACS), Leiden
7 * University.
8 */
9
10#ifndef _SYNTAXTREE_H_
11#define _SYNTAXTREE_H_
12
13#include <cstdlib>
14#include <string>
15#include <vector>
16#include <map>
17#include "Node.h"
18
19using namespace std;
20
21// ----------------------------------------------------------------------------
22// S Y N T A X T R E E
23// ----------------------------------------------------------------------------
24class SyntaxTree {
25
26 public:
27
28 // constructor
29 SyntaxTree (void);
30
31 // destructor
32 ~SyntaxTree (void);
33
34 // gets the program name
35 string GetProgramName (void);
36
37 // sets the program name
38 void SetProgramName (string name);
39
40 // gets the root node of the program body
41 Node * GetProgramBody (void);
42
43 // sets the root node of the program body
44 void SetProgramBody (Node * root);
45
46 // gets the number of subprograms
47 int GetSubprogramCount (void);
48
49 // gets the root node of the i-th subprogram
50 // 0 <= i < number of subprograms
51 Node * GetSubprogram (unsigned int i);
52
53 // gets the name of the i-th subprogram
54 string GetSubprogramName (unsigned int i);
55
56 // adds a subprogram
57 void AddSubprogram (string name, Node * root);
58
59 // creates an unary parent node
60 Node * CreateParentNode (NodeType nodeType,
61 ReturnType returnType,
62 Node * child);
63
64 // creates a binary parent node
65 Node * CreateParentNode (NodeType nodeType,
66 ReturnType ret,
67 Node * leftChild,
68 Node * rightChild);
69
70 // creates an integer leaf with node type NODE_NUM_INT
71 Node * CreateLeaf (int value);
72
73 // creates a real leaf with node type NODE_NUM_REAL
74 Node * CreateLeaf (float value);
75
76 // creates a symbol leaf with node type NODE_ID
77 Node * CreateLeaf (Symbol * symbol);
78
79 // creates a leaf with node type NODE_EMPTY
80 Node * CreateLeaf ();
81
82 // dumps the syntax tree
83 void Dump (FILE * file);
84
85 private:
86
87 string programName;
88 Node * programBody;
89 vector<string> subprogramNames;
90 vector<Node *> subprograms;
91 void DeleteTree (Node * root);
92
93};
94
95#endif
96
Note: See TracBrowser for help on using the repository browser.