diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 612616b..574f28f 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,7 +4,8 @@ "name": "Linux", "includePath": [ "${workspaceFolder}/include", - "${workspaceFolder}/**" + "${workspaceFolder}/**", + "${workspaceFolder}/lib/generated" ], "defines": [], "compilerPath": "/usr/lib64/ccache/clang", diff --git a/.vscode/settings.json b/.vscode/settings.json index 21e80e3..16651c6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,6 +9,67 @@ }, "files.associations": { "ostream": "cpp", - "iostream": "cpp" + "iostream": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "chrono": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ranges": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" } } \ No newline at end of file diff --git a/grammar/bfe.g4 b/grammar/bfe.g4 index ed58f2f..b1d0e36 100644 --- a/grammar/bfe.g4 +++ b/grammar/bfe.g4 @@ -74,9 +74,9 @@ LOOPEND:']'; GRPSTART:'('; GRPEND:')'; NUMBER: [0-9]+; -INPUT: '?'; +INPUT: ','; OUTPUT: '.'; DEC: '-'; INC: '+'; -LEFT: '>'; -RIGHT: '<'; +LEFT: '<'; +RIGHT: '>'; diff --git a/include/executeBFE.hpp b/include/executeBFE.hpp new file mode 100644 index 0000000..48f7132 --- /dev/null +++ b/include/executeBFE.hpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include "bfeParser.h" +#include "bfeBaseVisitor.h" + + +using namespace antlr4; +using namespace antlrcpp; +// using namespace std; +class executeBGE: public bfeBaseVisitor{ + private: + std::vector memory; + int pointer=0; + public: + executeBGE() : bfeBaseVisitor(),memory(100) { + } + // Any visitProgram(bfeParser::ProgramContext*) override; + Any visitNumberedStmt(bfeParser::NumberedStmtContext*) override; + Any visitPtrIncr(bfeParser::PtrIncrContext *ctx) override; + Any visitPtrDecr(bfeParser::PtrDecrContext *ctx) override; + Any visitPtrRight(bfeParser::PtrRightContext *ctx) override; + Any visitPtrLeft(bfeParser::PtrLeftContext *ctx) override; + Any visitInputStmt(bfeParser::InputStmtContext *ctx) override; + Any visitOutputStmt(bfeParser::OutputStmtContext *ctx) override; + Any visitLoopStmt(bfeParser::LoopStmtContext *ctx) override; +}; \ No newline at end of file diff --git a/samples/group.bfe b/samples/group.bfe index 8160e0e..0b88f87 100644 --- a/samples/group.bfe +++ b/samples/group.bfe @@ -1,2 +1,4 @@ -//should print ++++++ -(+2)3 \ No newline at end of file +//should print AAA +(+65>)3 +<<< +(.>)3 \ No newline at end of file diff --git a/src/executeBFE.cpp b/src/executeBFE.cpp new file mode 100644 index 0000000..92d5dc6 --- /dev/null +++ b/src/executeBFE.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include "bfeParser.h" +#include "bfeBaseVisitor.h" +#include "executeBFE.hpp" + + +using namespace antlr4; +using namespace antlrcpp; +using namespace std::__cxx11; + +Any executeBGE::visitNumberedStmt(bfeParser::NumberedStmtContext *ctx){ + int num = stoi(ctx->NUMBER()->getText()); + for(int i=0;istmt()->accept(this); + } + return Any(); +} + +Any executeBGE::visitPtrIncr(bfeParser::PtrIncrContext *ctx){ + memory[pointer]++; + return Any(); +} + +Any executeBGE::visitPtrDecr(bfeParser::PtrDecrContext *ctx){ + memory[pointer]--; + return Any(); +} + +Any executeBGE::visitPtrRight(bfeParser::PtrRightContext *ctx){ + pointer++; + return Any(); +} + +Any executeBGE::visitPtrLeft(bfeParser::PtrLeftContext *ctx){ + pointer--; + return Any(); +} + +Any executeBGE::visitInputStmt(bfeParser::InputStmtContext *ctx){ + std::cin>>memory[pointer]; + return Any(); +} + +Any executeBGE::visitOutputStmt(bfeParser::OutputStmtContext *ctx){ + std::cout<statements()->accept(this); + } + return Any(); +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 17b93c3..afda098 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "bfeLexer.h" #include "bfeParser.h" #include "toBFListener.hpp" +#include "executeBFE.hpp" using namespace antlr4; @@ -25,8 +26,10 @@ int main(int argc, const char *argv[]) bfeParser parser(&tokens); tree::ParseTree *tree = parser.program(); - toBFListener listener; - tree::ParseTreeWalker::DEFAULT.walk(&listener, tree); + // toBFListener listener; + // tree::ParseTreeWalker::DEFAULT.walk(&listener, tree); + executeBGE* visitor = new executeBGE(); + auto resultAny = visitor->visit(tree); return 0; } \ No newline at end of file