-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.hh
More file actions
90 lines (62 loc) · 1.89 KB
/
Copy pathdriver.hh
File metadata and controls
90 lines (62 loc) · 1.89 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# ifndef DRIVER_HH
# define DRIVER_HH
# include <string>
# include <map>
# include <set>
# include <fstream>
# include "types.hh"
# include "parser.hh"
#include "helpers/helpers.hh"
// Give Flex the prototype of yylex we want ...
# define YY_DECL \
yy::parser::symbol_type yylex (driver& drv)
// ... and declare it for the parser's sake.
YY_DECL;
// Conducting the whole scanning and parsing of Calc++.
class driver {
public:
driver ();
// ====> LABEL
std::string label_prefix;
int label_counter;
std::string get_label();
std::vector<std::map<std::string, std::string>> loop_labels_stack;
void push_loop();
void pop_loop();
// ====> SCOPE
int curr_scope;
void push_scope();
void pop_scope();
int in_loop;
int in_switch;
// ====> FUNCTIONS
std::map<std::string, Function> Functions;
Function get_function(std::string id, yy::location & loc);
void make_func(std::string id, int type);
void add_args_to_func(std::vector<Var> &vars, yy::location & loc);
std::string curr_function;
bool is_in_main;
// ====> VARIABLES
int global_offset;
int function_offset;
std::vector<std::map<std::string, Var>> variables;
Var get_variable(std::string id, yy::location & loc);
Var make_variable(std::string id, yy::location & loc, int type, int size, int initial_value);
bool has_variable_in_scope(std::string id, int scope);
// ====> CONSTANTS
std::vector<Constant> constants;
// ====> OUTPUT
void make_output(Node & node);
// ====> FILE
// Run the parser on file F. Return 0 on success.
int parse (const std::string& f);
// The name of the file being parsed.
std::string file;
// ====> SCANNER
// Handling the scanner.
void scan_begin ();
void scan_end ();
// Whether to generate scanner debug traces.
yy::location location;
};
#endif // ! DRIVER_HH