-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lisa.h
157 lines (131 loc) · 3.57 KB
/
Lisa.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// Lisa.h
// LISA
//
// Created by Naelin Aquino on 11/23/15.
// Copyright © 2015 Naelin Aquino. All rights reserved.
//
#ifndef Lisa_h
#define Lisa_h
#include <string>
#include <vector>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <functional>
#include <unordered_map>
namespace lisa
{
typedef std::unordered_multimap<std::string, int> umm;
typedef std::unordered_map<std::string, std::function<void(void)>> umm2;
umm variables;
umm2 functions;
void erase()
{
variables.erase("REG");
}
void start()
{
variables.insert(umm::value_type("REG", 0));
}
void done()
{
erase();
exit(0);
}
void input()
{
int val;
std::cin >> val;
erase();
variables.insert(umm::value_type("REG", val));
}
void output(std::string key)
{
auto range = variables.equal_range(key);
for(auto it = range.first; it != range.second; it++)
std::cout << it->second << " ";
std::cout << std::endl;
}
void plus(std::string x, std::string y)
{
if(variables.find(x) != variables.end() && variables.find(y) != variables.end())
{
erase();
variables.insert(umm::value_type("REG", variables.find(x)->second + variables.find(y)->second));
}
}
void minus(std::string x, std::string y)
{
if(variables.find(x) != variables.end() && variables.find(y) != variables.end())
{
erase();
variables.insert(umm::value_type("REG", variables.find(x)->second - variables.find(y)->second));
}
}
void store(std::string key)
{
variables.erase(key);
variables.insert(umm::value_type(key, variables.find("REG")->second));
}
void init(std::string key, int value)
{
variables.erase(key);
variables.insert(umm::value_type(key, value));
}
void inita(std::string key, int size, int arr[])
{
variables.erase(key);
for(int i = size - 1; i > -1; i--)
variables.insert(umm::value_type(key, arr[i]));
}
void put(std::string key, std::string y)
{
variables.erase(key);
variables.insert(umm::value_type(key, variables.find(y)->second));
}
void at(std::string key, int index)
{
auto range = variables.equal_range(key);
auto it = range.first;
for(int i = 0; i < index; i++)
it++;
erase();
variables.insert(umm::value_type("REG", it->second));
}
bool if_statement(std::string statement)
{
if(statement == "NEG")
return variables.find("REG")->second < 0;
else if(statement == "POS")
return variables.find("REG")->second > 0;
else if(statement == "ZERO")
return variables.find("REG")->second == 0;
else
exit(0);
}
void loop(std::string name)
{
auto range = functions.equal_range(name);
while(true)
{
for(auto it = range.first; it != range.second; it++)
it->second();
}
}
void func(std::string name, std::vector<std::function<void(void)>> funcs)
{
functions.erase(name);
for(int i = 0; i < funcs.size(); i++)
functions.insert(umm2::value_type(name, funcs[i]));
}
void go(std::string name)
{
auto range = functions.equal_range(name);
for(auto it = range.first; it != range.second; it++)
it->second();
}
}
// TODO: parse
// TODO: exception handling
#endif /* Lisa_h */