-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaxicality_config.cpp
More file actions
98 lines (87 loc) · 2.08 KB
/
taxicality_config.cpp
File metadata and controls
98 lines (87 loc) · 2.08 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
91
92
93
94
95
96
97
98
#include "taxicality_config.hpp"
#include <iostream>
#include <sstream>
#include <stack>
using std::cout;
using std::endl;
using std::stack;
std::list<Declaration>* root;
int current_line = 1;
unordered_map<string,Value> symtab;
string current_file;
stack<unordered_map<string,Value>> local_symtabs;
int inject_herald = 0;
string canonicalize(string identifier)
{
if(identifier=="assert")
return identifier;
if(local_symtabs.size())
{
unordered_map<string,Value>& local_symtab = local_symtabs.top();
if(local_symtab.count(identifier))
return identifier;
}
return identifier.find('.')!=string::npos ? identifier : (current_file+'.'+identifier);
}
Value& get_symbol(string identifier)
{
Value none = Value{Type::NONE};
string cid = canonicalize(identifier);
if(cid.find('.')==string::npos && cid!="assert")
{
if(!local_symtabs.top().count(cid))
local_symtabs.top()[cid] = none;
return local_symtabs.top()[cid];
}
else
{
if(!symtab.count(cid))
symtab[cid] = none;
return symtab[cid];
}
}
string get_type(Type type)
{
switch(type)
{
case Type::BOOLEAN: return "BOOLEAN";
case Type::NUMBER: return "NUMBER";
case Type::ARRAY: return "ARRAY";
default: return "unknown type";
}
}
string get_value(Value v)
{
ostringstream out;
out << get_type(v.type) << ": ";
switch(v.type)
{
case Type::BOOLEAN:
if(v.value.boolean)
out << "true";
else
out << "false";
break;
case Type::NUMBER:
out << v.value.number;
break;
case Type::ARRAY:
out << "(unimplemented)"; //TODO
}
return out.str();
}
extern "C" int yywrap()
{
//For now
return 1;
}
vector<string>* error_msgs;
int yyerror(const char* msg_)
{
string msg = "Line "+to_string(current_line)+": "+msg_;
if(error_msgs)
error_msgs->push_back(msg);
else
cout << msg << endl;
return 0;
}