source: liacs/coco/assignment3/Symbol.h@ 144

Last change on this file since 144 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.1 KB
Line 
1/*
2 * Symbol.h
3 *
4 * This file contains the declaration of the "Symbol" 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 _SYMBOL_H_
11#define _SYMBOL_H_
12
13#include <string>
14#include <vector>
15#include <cstdio>
16
17#include "types.h"
18
19using namespace std;
20
21// The base class for Symbols
22class Symbol {
23 public:
24 // Constructor/Destructor
25 Symbol (void);
26 virtual ~Symbol (void);
27
28 // Set the identifier text
29 void SetName (string name);
30
31 // Get the identifier text
32 string GetName (void);
33
34 // Set declaration line
35 void SetLine (int line);
36
37 // Get declaration line
38 int GetLine (void);
39
40 // Set return type
41 void SetReturnType (ReturnType type);
42
43 // Get return type
44 ReturnType GetReturnType (void);
45
46 // Set symbol type
47 void SetSymbolType (SymbolType type);
48
49 // Get symbol type
50 SymbolType GetSymbolType (void);
51
52 // Get offset (used during code generation)
53 int GetOffset();
54
55 // Set offset (used during code generation)
56 void SetOffset(int offset);
57
58 // Dump the contents
59 virtual void Dump (FILE * file, int indent);
60
61 // Virtuals (empty for this base class)
62 virtual void AddParameter (Symbol * symbol);
63 virtual int GetParameterCount (void);
64 virtual Symbol * GetParameter (unsigned int num);
65
66 private:
67 string myName;
68 int myLine;
69 ReturnType myReturnType;
70 SymbolType mySymbolType;
71 int myOffset;
72};//Symbol
73
74
75
76// Extended symbol class for functions and procedures
77class Symbol_Subprogram : public Symbol {
78 public:
79 // Destructor
80 ~Symbol_Subprogram (void);
81
82 // Add a parameter to the end of the parameter list
83 void AddParameter (Symbol * symbol);
84
85 // Get number of parameters
86 int GetParameterCount (void);
87
88 // Get the num-th argument
89 Symbol * GetParameter (unsigned int num);
90
91 // Dump
92 void Dump (FILE * file, int indent);
93
94 private:
95 vector<Symbol *> parameters;
96};//Symbol_Subprogram
97
98#endif
99
Note: See TracBrowser for help on using the repository browser.