boxscript-interperter-c/source/pcapp.cpp

47 lines
975 B
C++
Raw Normal View History

2022-12-01 03:27:30 +00:00
#if !defined(GEKKO)
#include "lexer.hpp"
#include "parser.hpp"
#include <filesystem>
namespace fs = std::filesystem;
using namespace BoxScript;
ListNode* _root_node;
std::string read_file(std::string name)
{
FILE* f=fopen(name.c_str(),"r");
std::string text="";
while(true)
{
int read = fgetc(f);
if(read == EOF) break;
text += (char)read;
}
fclose(f);
return text;
}
#if !defined(LIBRARY)
int main(int argc,char** argv)
{
if(argc < 2) return 1;
_root_node = new BoxScript::ListNode();
for(int i = 1;i<argc;i++){
std::vector<BoxScript::Lexer::LexToken> tokens=BoxScript::Lexer::Lex(read_file(argv[i]));
BoxScript::Parse(_root_node,tokens);
}
BoxScript::ApplicationState* state=new BoxScript::ApplicationState();
RegisterMainRuntimeFunctions(state);
_root_node->Evaluate(state);
DestroyApp(0);
}
#endif
void DestroyApp(int a)
{
delete _root_node;
exit(a);
}
#endif