Explorar el Código

Added help

master
Ludovic 'Archivist' Lagouardette hace 1 año
padre
commit
6136de1dc7
Se han modificado 3 ficheros con 52 adiciones y 1 borrados
  1. +1
    -1
      prototypes/molasses/basic_file.mol
  2. +7
    -0
      prototypes/molasses/other.mol
  3. +44
    -0
      src/main.cpp

+ 1
- 1
prototypes/molasses/basic_file.mol Ver fichero

@ -1,4 +1,4 @@
__PROC__ main
__--__
__DO__
__END__
__END__

+ 7
- 0
prototypes/molasses/other.mol Ver fichero

@ -0,0 +1,7 @@
__PROC__ add_mult
i32 i32 i32
__--__
i32
__DO__
+ *
__END__

+ 44
- 0
src/main.cpp Ver fichero

@ -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<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";
}
}
}
}

Cargando…
Cancelar
Guardar