-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyzer.h
51 lines (34 loc) · 868 Bytes
/
analyzer.h
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
#ifndef ANALYZER_H
#define ANALYZER_H
#include <unordered_map>
#include <list>
#include "parser.h"
struct TreeNode;
struct Symbol
{
std::string name;
size_t location;
std::list<size_t> lines;
};
class Analyzer
{
public:
Analyzer(Parser & parser);
void analysis();
TreeNode * root() { return parser_.root(); }
size_t findSymbol(const std::string & name);
void printSymbolTable();
private:
void typeCheck();
void buildSymbolTable();
void traverse(TreeNode * t, auto pre, auto post);
void checkNode(TreeNode * t);
void typeCheckError(TreeNode * t, const char *);
void typeCheck(TreeNode * t);
void buildSymbolTable(TreeNode * t);
void insertSymbol(TreeNode * t);
Parser & parser_;
std::unordered_map<std::string, Symbol> symbol_table_;
size_t location_;
};
#endif // ANALYZER_H