#include "nasal.h" nasal_resource resource; nasal_lexer lexer; nasal_parse parse; std::string command; nasal_runtime runtime; void help() { std::cout<<">> [\'file\'] input a file."<> [cls ] clear the screen."<> [clear ] clear the screen."<> [del ] clear the resource code."<> [lib ] add lib file."<> [rs ] print resource code."<> [lex ] turn code into tokens."<> [par ] turn tokens into abstract syntax tree."<> [ast ] check the abstract syntax tree."<> [run ] run code."<> [logo ] print logo of nasal ."<> [exit ] quit nasal interpreter."<> [Delete] complete."<> [lexer] error(s) occurred,stop.\n"; return; } void par_func() { lexer.scanner(resource.get_file()); if(!lexer.get_error()) { parse.set_toklist(lexer.get_token_list()); parse.main_process(); if(parse.get_error()) std::cout<<">> [parse] error(s) occurred,stop.\n"; } else std::cout<<">> [lexer] error(s) occurred,stop.\n"; return; } void ast_print() { lexer.scanner(resource.get_file()); if(!lexer.get_error()) { parse.set_toklist(lexer.get_token_list()); parse.main_process(); if(parse.get_error()) std::cout<<">> [parse] error(s) occurred,stop.\n"; else parse.get_root().print_ast(0); } else std::cout<<">> [lexer] error(s) occurred,stop.\n"; return; } void runtime_start() { lexer.scanner(resource.get_file()); if(!lexer.get_error()) { parse.set_toklist(lexer.get_token_list()); parse.main_process(); if(parse.get_error()) std::cout<<">> [parse] error(s) occurred,stop.\n"; else { runtime.set_root(parse.get_root()); runtime.run(); } } else std::cout<<">> [lexer] error(s) occurred,stop.\n"; return; } int main() { #ifdef _WIN32 // use chcp 65001 to use unicode io system("chcp 65001"); system("cls"); #endif // this curve looks really cool logo(); #ifdef _WIN32 std::cout<<">> [system] Windows system."<> [system] Linux system."<> [system] MacOS system."<> Nasal interpreter ver 3.0 ."<> Code: https://github.com/ValKmjolnir/Nasal-Interpreter"<> More info: http://wiki.flightgear.org/Nasal_scripting_language"<> Input \"help\" to get help ."<> "; std::cin>>command; if(command=="help") help(); else if(command=="cls" || command=="clear") { #ifdef _WIN32 system("cls"); #endif #ifdef _linux_ system("clear"); #endif #ifdef TARGET_OS_MAC system("clear"); #endif } else if(command=="del") del_func(); else if(command=="lib") resource.load_lib(); else if(command=="rs") resource.print_file(); else if(command=="lex") lex_func(); else if(command=="par") par_func(); else if(command=="ast") ast_print(); else if(command=="run") runtime_start(); else if(command=="logo") logo(); else if(command=="exit") break; else resource.input_file(command); } return 0; }