-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntime.h
86 lines (67 loc) · 1.44 KB
/
runtime.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
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
#include <map>
#include <vector>
#ifndef PARSER_H
#include "parser.h"
#endif
#ifndef RUNTIME_H
#define RUNTIME_H
#endif
struct symbol_t {
enum type_t {
INT,
REAL,
PROC,
INT_KONST
} type;
union {
int intValue;
int procIndex;
double realValue;
};
};
std::ostream& operator<<( std::ostream& os, const symbol_t& symbol );
struct symtable_t {
map<string, symbol_t> symbols;
symtable_t* parent;
vector<symtable_t*> children;
symbol_t* lookup( string identifier );
};
std::ostream& operator<<( std::ostream& os, const symtable_t& symbol );
struct value_t {
enum type_t {
INT, REAL
} type;
union {
double realValue;
int intValue;
};
};
struct program_t {
symtable_t table;
vector<token_t> tokens;
int position;
symtable_t* current;
vector<value_t> arguments;
void run(vector<string>&);
private:
void constdecl();
void vardecl();
void procdecl();
value_t factor();
value_t term();
value_t exp();
bool condition();
void statement();
void program(vector<string>&);
void block();
void skip_procedure();
void skip_block();
void skip_expression();
void skip_term();
void skip_factor();
void skip_statement();
void skip_condition();
};
void run_const( program_t& prg );
void run_block( program_t& prg );
void run_program( program_t& prg );