diff --git a/prototypes/molasses/basic_file.mol b/prototypes/molasses/basic_file.mol index d69e258..15e8ac1 100644 --- a/prototypes/molasses/basic_file.mol +++ b/prototypes/molasses/basic_file.mol @@ -1,4 +1,4 @@ __PROC__ main __--__ __DO__ -__END__ \ No newline at end of file +__END__ diff --git a/prototypes/molasses/other.mol b/prototypes/molasses/other.mol new file mode 100644 index 0000000..1eff699 --- /dev/null +++ b/prototypes/molasses/other.mol @@ -0,0 +1,7 @@ +__PROC__ add_mult +i32 i32 i32 +__--__ +i32 +__DO__ ++ * +__END__ \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 5e5c871..91752c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,6 +80,50 @@ int main(int argc, char** argv) { std::cout << link.str() << std::endl; system(link.str().c_str()); } 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); } + + if(compile_stack.size() > 1) throw std::runtime_error("build left unfinished operations"); + if(not compile_stack.empty()) { + if(std::holds_alternative(compile_stack.top())) { + auto lexer = std::get(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(compile_stack.top())) { + auto generator = std::get(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"; + } + } + } }