diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 574f28f..9ec55e6 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,13 +4,14 @@ "name": "Linux", "includePath": [ "${workspaceFolder}/include", - "${workspaceFolder}/**", + "${workspaceFolder}/lib/antlr4/include", + "${workspaceFolder}/lib/cxxopts/include", "${workspaceFolder}/lib/generated" ], "defines": [], "compilerPath": "/usr/lib64/ccache/clang", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++11", "intelliSenseMode": "clang-x64", "configurationProvider": "ms-vscode.cmake-tools" } diff --git a/.vscode/launch.json b/.vscode/launch.json index 3ff6721..4f21796 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -57,6 +57,25 @@ "ignoreFailures": true } ] + }, + { + "name": "GDB - error.bfe", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/main.out", + "args": ["samples/error.bfe"], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 16651c6..1dc32be 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -70,6 +70,8 @@ "streambuf": "cpp", "thread": "cpp", "cinttypes": "cpp", - "typeinfo": "cpp" + "typeinfo": "cpp", + "regex": "cpp", + "shared_mutex": "cpp" } } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 83961ed..f84838f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,5 +27,6 @@ target_include_directories(main.out ${PROJECT_SOURCE_DIR}/lib/generated ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/lib/antlr4/include + ${PROJECT_SOURCE_DIR}/lib/cxxopts/include ) diff --git a/README.md b/README.md index 214c532..fdd623c 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ An extension of a language that shall not be named +Requires: +1. cxxopts -> v2.2.1 +2. antlr4 + + *HelloWorld.bfe* ``` -[-7>+<]>-.-[->+5<]>++.+7..+3.[-3>+<]>-5.--[->+4<]>-.-8.+3.-6.-8. diff --git a/samples/error.bfe b/samples/error.bfe index e69de29..0ba4077 100644 --- a/samples/error.bfe +++ b/samples/error.bfe @@ -0,0 +1 @@ ++65.< \ No newline at end of file diff --git a/src/executeBFE.cpp b/src/executeBFE.cpp index 1fca687..8372851 100644 --- a/src/executeBFE.cpp +++ b/src/executeBFE.cpp @@ -38,6 +38,7 @@ Any executeBGE::visitPtrRight(bfeParser::PtrRightContext *ctx){ } Any executeBGE::visitPtrLeft(bfeParser::PtrLeftContext *ctx){ + if(pointer==0) throw std::string("Decrement below zero"); pointer--; return Any(); diff --git a/src/main.cpp b/src/main.cpp index 404f21a..bac1d72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,39 +1,70 @@ #include #include #include -#include +#include +#include "antlr4-common.h" +#include "cxxopts.hpp" #include "bfeLexer.h" #include "bfeParser.h" #include "toBFListener.hpp" #include "executeBFE.hpp" - using namespace antlr4; -int main(int argc, const char *argv[]) +int main(int argc, char **argv) { - std::ifstream stream; - bool outFile = false; - stream.open(argv[1]); - if (stream.fail()) + cxxopts::Options options(argv[0], "An interpreter/translator for bfe"); + + options.add_options() + ("t,translate", "Translate to bf", cxxopts::value()->default_value("false")) + ("i,input", "Input(First argument)", cxxopts::value()) + ("h,help", "Print usage"); + options.parse_positional({"input"}); + auto results = options.parse(argc, argv); + if (results.count("help")) { - std::cout << "Could not open" << std::endl; + std::cout << options.help() << std::endl; + return 0; + } + if (results.count("input")) + { + // std::cout << results["input"].as()<()); + if (stream.fail()) + { + std::cout << "Could not open" << std::endl; + return 1; + } + ANTLRInputStream input(stream); + bfeLexer lexer(&input); + CommonTokenStream tokens(&lexer); + bfeParser parser(&tokens); + + tree::ParseTree *tree = parser.program(); + if(results["translate"].as()){ + toBFListener listener; + tree::ParseTreeWalker::DEFAULT.walk(&listener, tree); + }else{ + executeBGE *visitor = new executeBGE(); + try + { + visitor->visit(tree); + std::cout << std::endl; + } + catch (std::string e) + { + std::cout << "\nIllegal:" << e<visit(tree); - std::cout<2 && ) return 0; } \ No newline at end of file