|
|
|
@ -19,40 +19,59 @@
|
|
|
|
|
#include "memdict.hpp"
|
|
|
|
|
#include "parser.hpp"
|
|
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
// : variable create 0 , ;
|
|
|
|
|
// : create here constant ;
|
|
|
|
|
// : constant
|
|
|
|
|
static void parseLine(Parser&, State&, std::string_view);
|
|
|
|
|
static void parseFile(Parser&, State&, std::istream&);
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
MemDict dict;
|
|
|
|
|
State state (dict);
|
|
|
|
|
Parser parser;
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
std::string line;
|
|
|
|
|
std::cout << state.size() << ' ' << state.compiling << "> ";
|
|
|
|
|
std::getline(std::cin, line);
|
|
|
|
|
|
|
|
|
|
ParseStatus r;
|
|
|
|
|
std::string_view lv (line);
|
|
|
|
|
do {
|
|
|
|
|
r = parser.parse(state, lv);
|
|
|
|
|
} while (r == ParseStatus::Continue);
|
|
|
|
|
|
|
|
|
|
if (r != ParseStatus::Finished)
|
|
|
|
|
std::cout << "r " << to_string(r) << std::endl;
|
|
|
|
|
std::vector args (argv + 1, argv + argc);
|
|
|
|
|
for (const auto& a : args) {
|
|
|
|
|
std::ifstream file (a);
|
|
|
|
|
parseFile(parser, state, file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//std::cout << state.size() << ' ' << state.compiling << "> ";
|
|
|
|
|
parseFile(parser, state, std::cin);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int user_sys(State& state)
|
|
|
|
|
{
|
|
|
|
|
const auto value = state.pop();
|
|
|
|
|
std::cout << value << std::endl;
|
|
|
|
|
switch (state.pop()) {
|
|
|
|
|
case 0:
|
|
|
|
|
std::cout << state.pop() << std::endl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void parseLine(Parser& parser, State& state, std::string_view line)
|
|
|
|
|
{
|
|
|
|
|
ParseStatus r;
|
|
|
|
|
do {
|
|
|
|
|
r = parser.parse(state, line);
|
|
|
|
|
} while (r == ParseStatus::Continue);
|
|
|
|
|
|
|
|
|
|
if (r != ParseStatus::Finished)
|
|
|
|
|
std::cout << "r " << to_string(r) << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void parseFile(Parser& parser, State& state, std::istream& file)
|
|
|
|
|
{
|
|
|
|
|
while (file.good()) {
|
|
|
|
|
std::string line;
|
|
|
|
|
std::getline(file, line);
|
|
|
|
|
parseLine(parser, state, line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|