static SplitMemDict<alee_dat_len> dict (alee_dat);
State state (dict, readchar);
- Parser parser;
serputs("alee forth\n\r");
serputs("\n\r");
- if (auto r = parser.parse(state, strbuf); r == 0) {
+ if (auto r = Parser::parse(state, strbuf); r == 0) {
serputs(state.compiling() ? " compiled" : " ok");
} else {
switch (r) {
case 1:
serput(state.pop());
break;
+ case 2:
+ { auto addr = state.pop();
+ *((uint8_t *)addr) = state.pop(); }
+ break;
+ case 3:
+ state.push(*((uint8_t *)state.pop()));
+ break;
default:
break;
}
static bool okay = false;
static void readchar(State& state);
-static void parseLine(Parser&, State&, const std::string&);
-static void parseFile(Parser&, State&, std::istream&);
-
-static Parser parser;
+static void parseLine(State&, const std::string&);
+static void parseFile(State&, std::istream&);
int main(int argc, char *argv[])
{
std::vector args (argv + 1, argv + argc);
for (const auto& a : args) {
std::ifstream file (a);
- parseFile(parser, state, file);
+ parseFile(state, file);
}
okay = true;
- parseFile(parser, state, std::cin);
+ parseFile(state, std::cin);
return 0;
}
std::jmp_buf oldjb;
memcpy(oldjb, state.jmpbuf, sizeof(std::jmp_buf));
state.ip = 0;
- parser.parseSource(state);
+ Parser::parseSource(state);
memcpy(state.jmpbuf, oldjb, sizeof(std::jmp_buf));
state.ip = oldip;
}
}
}
-void parseLine(Parser& parser, State& state, const std::string& line)
+void parseLine(State& state, const std::string& line)
{
- if (auto r = parser.parse(state, line.c_str()); r == 0) {
+ if (auto r = Parser::parse(state, line.c_str()); r == 0) {
if (okay)
std::cout << (state.compiling() ? "compiled" : "ok") << std::endl;
} else {
}
}
-void parseFile(Parser& parser, State& state, std::istream& file)
+void parseFile(State& state, std::istream& file)
{
while (file.good()) {
std::string line;
if (line == "bye")
exit(0);
- parseLine(parser, state, line);
+ parseLine(state, line);
}
}
static bool okay = false;
static void readchar(State& state);
-static void parseLine(Parser&, State&, const std::string&);
-static void parseFile(Parser&, State&, std::istream&);
-
-static Parser parser;
+static void parseLine(State&, const std::string&);
+static void parseFile(State&, std::istream&);
int main(int argc, char *argv[])
{
std::vector args (argv + 1, argv + argc);
for (const auto& a : args) {
std::ifstream file (a);
- parseFile(parser, state, file);
+ parseFile(state, file);
}
}
okay = true;
- parseFile(parser, state, std::cin);
+ parseFile(state, std::cin);
return 0;
}
std::jmp_buf oldjb;
memcpy(oldjb, state.jmpbuf, sizeof(std::jmp_buf));
state.ip = 0;
- parser.parseSource(state);
+ Parser::parseSource(state);
memcpy(state.jmpbuf, oldjb, sizeof(std::jmp_buf));
state.ip = oldip;
}
}
}
-void parseLine(Parser& parser, State& state, const std::string& line)
+void parseLine(State& state, const std::string& line)
{
- if (auto r = parser.parse(state, line.c_str()); r == 0) {
+ if (auto r = Parser::parse(state, line.c_str()); r == 0) {
if (okay)
std::cout << (state.compiling() ? "compiled" : "ok") << std::endl;
} else {
}
}
-void parseFile(Parser& parser, State& state, std::istream& file)
+void parseFile(State& state, std::istream& file)
{
while (file.good()) {
std::string line;
if (line == "bye")
exit(0);
- parseLine(parser, state, line);
+ parseLine(state, line);
}
}
public:
constexpr static int UnknownWord = -1;
- int parse(State&, const char *);
- int parseSource(State&);
+ static int parse(State&, const char *);
+ static int parseSource(State&);
private:
- int parseWord(State&, Word);
- int parseNumber(State&, Word);
+ static int parseWord(State&, Word);
+ static int parseNumber(State&, Word);
};
#endif // ALEEFORTH_PARSER_HPP