-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsetree.h
executable file
·59 lines (38 loc) · 1.24 KB
/
parsetree.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
52
53
54
55
56
57
58
59
#ifndef PARSE_TREE
#define PARSE_TREE
/* parsetree.h
Alistair Campbell
2015--2019
Modified Fall 2019: separate into .h and .cc files
*/
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include "tokentype.h"
#include "semantics.h"
/* prototype for yyerror, needed on my linux laptop */
int yyerror(const char * s);
using namespace std;
struct ParseTree {
string description;
Token * token; // nullptr for nonterminal trees
semantics * sem;
Symtab *symtab; // new: attach a symbol table to a parse tree.
vector<ParseTree *> children; // empty for terminal trees
S_type * type;
ParseTree(string description, ParseTree* c1);
ParseTree(string description, ParseTree* c1, ParseTree* c2);
ParseTree(string description, ParseTree* c1, ParseTree* c2, ParseTree *c3);
ParseTree(string description, ParseTree* c1, ParseTree* c2, ParseTree *c3,
ParseTree *c4);
ParseTree(string description);
ParseTree(Token * tokp);
void addChild(ParseTree * tree);
void addChild(ParseTree * tree1, ParseTree * tree2);
string toString() const;
};
string base26(int x);
string seq2str(int seq, int depth);
void traverseTree(ParseTree * tree, int depth, int seq);
#endif