|
@ -80,6 +80,50 @@ int main(int argc, char** argv) { |
|
|
std::cout << link.str() << std::endl; |
|
|
std::cout << link.str() << std::endl; |
|
|
system(link.str().c_str()); |
|
|
system(link.str().c_str()); |
|
|
} else throw std::runtime_error("assemble expects an assembly file"); |
|
|
} else throw std::runtime_error("assemble expects an assembly file"); |
|
|
|
|
|
} else if(elem == "help" or elem == "--help") { |
|
|
|
|
|
std::cout << "lex : string -> lexed_output\n"; |
|
|
|
|
|
std::cout << "merge : lexed_output lexed_output -> lexed_output\n"; |
|
|
|
|
|
std::cout << "parse : lexed_output -> parsed_output\n"; |
|
|
|
|
|
std::cout << "generate : parsed_output string -> string\n"; |
|
|
|
|
|
std::cout << "assemble : string -> \n"; |
|
|
|
|
|
std::cout << "help : -> \n"; |
|
|
|
|
|
std::cout << "\n"; |
|
|
|
|
|
std::cout << "examples:\n"; |
|
|
|
|
|
std::cout << "\tcompile the file \"example.mol\" into the \"potato.s\" assembly file\n"; |
|
|
|
|
|
std::cout << "\t$ sugar example.mol lex parse potato generate\n"; |
|
|
|
|
|
std::cout << "\n"; |
|
|
|
|
|
std::cout << "\tcompile the file \"example.mol\" into the \"potato\" executable\n"; |
|
|
|
|
|
std::cout << "\t$ sugar example.mol lex parse potato generate assemble\n"; |
|
|
|
|
|
std::cout << "\n"; |
|
|
|
|
|
std::cout << "\tcompile the file \"example.mol\" and \"2.mol\" into the \"potato\" executable\n"; |
|
|
|
|
|
std::cout << "\t$ sugar example.mol lex 2.mol lex merge parse potato generate assemble\n"; |
|
|
} else compile_stack.emplace(elem); |
|
|
} else compile_stack.emplace(elem); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(compile_stack.size() > 1) throw std::runtime_error("build left unfinished operations"); |
|
|
|
|
|
if(not compile_stack.empty()) { |
|
|
|
|
|
if(std::holds_alternative<molasses::lexed_output>(compile_stack.top())) { |
|
|
|
|
|
auto lexer = std::get<molasses::lexed_output>(compile_stack.top()); |
|
|
|
|
|
for(auto elem : lexer.symbols) { |
|
|
|
|
|
std::cout << elem << " "; |
|
|
|
|
|
} |
|
|
|
|
|
std::cout << "\n\n"; |
|
|
|
|
|
for(auto [id, name] : lexer.dictionary) { |
|
|
|
|
|
std::cout << id << ": " << name << "\n"; |
|
|
|
|
|
} |
|
|
|
|
|
} else if(std::holds_alternative<molasses::generate_context>(compile_stack.top())) { |
|
|
|
|
|
auto generator = std::get<molasses::generate_context>(compile_stack.top()); |
|
|
|
|
|
for(const auto& elem : generator.procedures) { |
|
|
|
|
|
std::cout << elem->_name << " : "; |
|
|
|
|
|
for(const auto& args : elem->_args) { |
|
|
|
|
|
std::cout << args << " "; |
|
|
|
|
|
} |
|
|
|
|
|
std::cout << "->"; |
|
|
|
|
|
for(const auto& rets : elem->_rets) { |
|
|
|
|
|
std::cout << " " << rets; |
|
|
|
|
|
} |
|
|
|
|
|
std::cout << "\n"; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |