From c761418ccc1c4bca0138e284fa688e3155ce25cf Mon Sep 17 00:00:00 2001 From: ferhatgec Date: Sun, 27 Dec 2020 10:37:44 +0300 Subject: [PATCH] Add: untyp --- flascript/Interpreter/Interpreter.cpp | 13 ++++++---- flascript/Interpreter/Print.cpp | 29 ++++++++++++++------- flascript/Interpreter/Tools.cpp | 37 +++++++++++++++------------ include/Interpreter/Tools.hpp | 8 +++++- test.fls | 6 +++-- 5 files changed, 60 insertions(+), 33 deletions(-) diff --git a/flascript/Interpreter/Interpreter.cpp b/flascript/Interpreter/Interpreter.cpp index e23c3ba..3f186a4 100644 --- a/flascript/Interpreter/Interpreter.cpp +++ b/flascript/Interpreter/Interpreter.cpp @@ -156,6 +156,7 @@ FInterpreter::FlaScriptImporter(std::string file, std::string get) { */ void FInterpreter::FlaScriptInterpreterWithArg(std::string file, std::string arg) { + FTools seq; Tokenizer token; std::string strarg; std::istringstream argline(arg); @@ -195,7 +196,7 @@ FInterpreter::FlaScriptInterpreterWithArg(std::string file, std::string arg) { BOLD_RED_COLOR std::cout << "error: "; - get_data = FlaScript::EscapeSeq(get_data); + get_data = seq.EscapeSeq(get_data); BOLD_LIGHT_WHITE_COLOR std::cout << get_data + "\n"; @@ -214,7 +215,7 @@ FInterpreter::FlaScriptInterpreterWithArg(std::string file, std::string arg) { BOLD_YELLOW_COLOR std::cout << "warning: "; - get_data = FlaScript::EscapeSeq(get_data); + get_data = seq.EscapeSeq(get_data); BOLD_LIGHT_WHITE_COLOR std::cout << get_data + "\n"; @@ -231,7 +232,7 @@ FInterpreter::FlaScriptInterpreterWithArg(std::string file, std::string arg) { BOLD_LIGHT_GREEN_COLOR std::cout << "success: "; - get_data = FlaScript::EscapeSeq(get_data); + get_data = seq.EscapeSeq(get_data); BOLD_LIGHT_WHITE_COLOR std::cout << get_data + "\n"; @@ -402,7 +403,7 @@ FInterpreter::FlaScriptInterpreterWithArg(std::string file, std::string arg) { std::string get_data = var.GetVariable(get_name); if(get_name != "error") { - get_data = FlaScript::EscapeSeq(get_data); + get_data = seq.EscapeSeq(get_data); var.Equal(get_name, get_data); } @@ -1127,7 +1128,9 @@ FInterpreter::FlaScriptInterpreter(flascript_t &data) { std::string get_data = var.GetVariable(get_name); if(get_name != "error") { - get_data = FlaScript::EscapeSeq(get_data); + FTools seq; + + get_data = seq.EscapeSeq(get_data); var.Equal(get_name, get_data); } diff --git a/flascript/Interpreter/Print.cpp b/flascript/Interpreter/Print.cpp index 3dc1fbc..7b0e4a2 100644 --- a/flascript/Interpreter/Print.cpp +++ b/flascript/Interpreter/Print.cpp @@ -61,6 +61,7 @@ FPrint::Print(std::string file, std::string arg) { FInterpreter inp; FFunction func; FVariable var; + FTools seq; if(inp.FindObject(arg, "fprintf") == true || inp.FindObject(arg, "fprintln") == true) { // fprintf(<%string>[:"test":, :"hello":]) std::string assign, type; @@ -107,12 +108,20 @@ FPrint::Print(std::string file, std::string arg) { std::string assign; stringtools::GetBtwString(arg, "(", ")", assign); - if(assign == "string") { - stringtools::GetBtwString(arg, " \"", "\"", assign); - assign = FlaScript::EscapeSeq(assign); - - if(assign != "error") - std::cout << assign; + if(assign[0] == '"' || assign == "string" || assign == "untyp") { + + if(assign == "string") { + stringtools::GetBtwString(arg, "\"", "\"", assign); + assign = seq.EscapeSeq(assign); + } else if(assign == "untyp") { + stringtools::GetBtwString(arg, "\"", "\"", assign); + assign = seq.StandardSeq(assign); + } else { + stringtools::GetBtwString(assign, "\"", "\"", assign); + assign = seq.EscapeSeq(assign); + } + + if(assign != "error") std::cout << assign; } else if(inp.FindObject(assign, "var") == true) { stringtools::GetBtwString(assign, "[", "]", assign); @@ -273,7 +282,7 @@ FPrint::Print(std::string file, std::string arg) { stringtools::GetBtwString(arg, " \"", "\"", assign); if(assign != "error") { - assign = FlaScript::EscapeSeq(assign); + assign = seq.EscapeSeq(assign); std::cout << assign << "\n"; } else @@ -293,7 +302,7 @@ FPrint::Print(std::string file, std::string arg) { stringtools::GetBtwString(get, " ", ":", color); stringtools::GetBtwString(arg, " \"", "\" <-", assign); - assign = FlaScript::EscapeSeq(assign); + assign = seq.EscapeSeq(assign); if(assign == "error") { stringtools::GetBtwString(arg, " \"", "\"", assign); @@ -319,7 +328,7 @@ FPrint::Print(std::string file, std::string arg) { stringtools::GetBtwString(get, " ", ":", color); stringtools::GetBtwString(arg, " \"", "\" <-", assign); - assign = FlaScript::EscapeSeq(assign); + assign = seq.EscapeSeq(assign); if(assign == "error") { stringtools::GetBtwString(arg, " \"", "\"", assign); @@ -335,6 +344,8 @@ FPrint::Print(std::string file, std::string arg) { if (t != var_.end()) // Found std::cout << t->second; } + } else { + /* error, undefined type */ } } } diff --git a/flascript/Interpreter/Tools.cpp b/flascript/Interpreter/Tools.cpp index 777f274..7bef102 100644 --- a/flascript/Interpreter/Tools.cpp +++ b/flascript/Interpreter/Tools.cpp @@ -30,27 +30,15 @@ #endif void -FlaScript::TextBackground(int color) { +FTools::TextBackground(int color) { printf("%c[%dm", ESC, 40+color); } - - std::string -FlaScript::EscapeSeq(std::string data) { - stringtools::replaceAll(data, "\\033", "\033"); - stringtools::replaceAll(data, "\\x1", "\x1"); - stringtools::replaceAll(data, "\\x2", "\x2"); - stringtools::replaceAll(data, "\\x3", "\x3"); - - stringtools::replaceAll(data, "\\n", "\n"); - stringtools::replaceAll(data, "\\t", "\t"); - stringtools::replaceAll(data, "\\a", "\a"); - stringtools::replaceAll(data, "\\b", "\b"); - stringtools::replaceAll(data, "\\v", "\v"); - stringtools::replaceAll(data, "\\r", "\r"); +FTools::EscapeSeq(std::string data) { + data = Sequence(data); - if(stringtools::Count(data, '{') == stringtools::Count(data, '}')) { + if(stringtools::Count(data, '{') == stringtools::Count(data, '}')) { unsigned i = stringtools::Count(data, '{'); FVariable var; @@ -68,3 +56,20 @@ FlaScript::EscapeSeq(std::string data) { return data; } + +std::string +FTools::Sequence(std::string data) { + stringtools::replaceAll(data, "\\033", "\033"); + stringtools::replaceAll(data, "\\x1", "\x1"); + stringtools::replaceAll(data, "\\x2", "\x2"); + stringtools::replaceAll(data, "\\x3", "\x3"); + + stringtools::replaceAll(data, "\\n", "\n"); + stringtools::replaceAll(data, "\\t", "\t"); + stringtools::replaceAll(data, "\\a", "\a"); + stringtools::replaceAll(data, "\\b", "\b"); + stringtools::replaceAll(data, "\\v", "\v"); + stringtools::replaceAll(data, "\\r", "\r"); + + return data; +} diff --git a/include/Interpreter/Tools.hpp b/include/Interpreter/Tools.hpp index 5d9ae73..029515b 100644 --- a/include/Interpreter/Tools.hpp +++ b/include/Interpreter/Tools.hpp @@ -11,10 +11,16 @@ #include #include -namespace FlaScript { +class FTools { +public: void TextBackground(int); std::string EscapeSeq(std::string data); + std::string Sequence(std::string data); + + std::string StandardSeq(std::string data) { + return Sequence(data); + } }; #endif // TOOLS_HPP diff --git a/test.fls b/test.fls index 1e750e2..4e85b8b 100644 --- a/test.fls +++ b/test.fls @@ -1,7 +1,8 @@ main() -> main { var(string) -> FlaHello, developerFla -> pop <- - print(string) -> "String: {pop}\n" + print(untyp) -> "Variable: {pop}\n" + print("String: {pop}\n") @pop_front -> pop < @pop_front -> pop < @@ -11,5 +12,6 @@ main() -> main { @pop_back -> pop < @pop_back -> pop < - print(string) -> "String: {pop}\n" + print(string) "String: {pop}\n" + } main;