diff --git a/.vscode/settings.json b/.vscode/settings.json index 6e150ab..21e80e3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ "outputDir": "../lib/generated" }, "files.associations": { - "ostream": "cpp" + "ostream": "cpp", + "iostream": "cpp" } } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e50c42a..83961ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,12 +10,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) set(SOURCES src/main.cpp src/toBFListener.cpp - lib/generated/bfLexer.cpp - lib/generated/bfParser.cpp - lib/generated/bfBaseVisitor.cpp - lib/generated/bfVisitor.cpp - lib/generated/bfBaseListener.cpp - lib/generated/bfListener.cpp + src/executeBFE.cpp + lib/generated/bfeLexer.cpp + lib/generated/bfeParser.cpp + lib/generated/bfeBaseVisitor.cpp + lib/generated/bfeVisitor.cpp + lib/generated/bfeBaseListener.cpp + lib/generated/bfeListener.cpp ) add_executable(main.out ${SOURCES}) diff --git a/README.md b/README.md index 0974bf5..f131171 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ An extension of a language that shall not be named - [ ] Grammar - [X] Number shorthand - [X] Loop statements - - [ ] shorthand segments + - [ ] Shorthand segments - [ ] Processing - - [X] Print resultant .bf - - [ ] execute result \ No newline at end of file + - [X] Translate to bf + - [ ] Execute result \ No newline at end of file diff --git a/grammar/bf.g4 b/grammar/bfe.g4 similarity index 98% rename from grammar/bf.g4 rename to grammar/bfe.g4 index 5b66dd7..ed58f2f 100644 --- a/grammar/bf.g4 +++ b/grammar/bfe.g4 @@ -1,4 +1,4 @@ -grammar bf; +grammar bfe; program : statements? EOF; diff --git a/include/toBFListener.hpp b/include/toBFListener.hpp index fd31166..08ab789 100644 --- a/include/toBFListener.hpp +++ b/include/toBFListener.hpp @@ -1,25 +1,25 @@ #pragma once #include -#include "bfLexer.h" -#include "bfParser.h" -#include "bfBaseListener.h" +#include "bfeLexer.h" +#include "bfeParser.h" +#include "bfeBaseListener.h" -class toBFListener : public bfBaseListener { +class toBFListener : public bfeBaseListener { protected: std::vector printStack; public: - void enterProgram(bfParser::ProgramContext *ctx) override; - void exitProgram(bfParser::ProgramContext *ctx) override ; - void enterPtrIncr(bfParser::PtrIncrContext *ctx) override; - void enterPtrDecr(bfParser::PtrDecrContext *ctx) override; - void enterPtrLeft(bfParser::PtrLeftContext *ctx) override; - void enterPtrRight(bfParser::PtrRightContext *ctx) override; - void enterNumberedStmt(bfParser::NumberedStmtContext *ctx) override; - void exitNumberedStmt(bfParser::NumberedStmtContext *ctx) override; - void enterLoopStmt(bfParser::LoopStmtContext *ctx) override; - void exitLoopStmt(bfParser::LoopStmtContext *ctx) override; - void enterGroupedStmt(bfParser::GroupedStmtContext *ctx) override; - void exitGroupedStmt(bfParser::GroupedStmtContext *ctx) override; + void enterProgram(bfeParser::ProgramContext *ctx) override; + void exitProgram(bfeParser::ProgramContext *ctx) override ; + void enterPtrIncr(bfeParser::PtrIncrContext *ctx) override; + void enterPtrDecr(bfeParser::PtrDecrContext *ctx) override; + void enterPtrLeft(bfeParser::PtrLeftContext *ctx) override; + void enterPtrRight(bfeParser::PtrRightContext *ctx) override; + void enterNumberedStmt(bfeParser::NumberedStmtContext *ctx) override; + void exitNumberedStmt(bfeParser::NumberedStmtContext *ctx) override; + void enterLoopStmt(bfeParser::LoopStmtContext *ctx) override; + void exitLoopStmt(bfeParser::LoopStmtContext *ctx) override; + void enterGroupedStmt(bfeParser::GroupedStmtContext *ctx) override; + void exitGroupedStmt(bfeParser::GroupedStmtContext *ctx) override; }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 47459a5..17b93c3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,11 +2,10 @@ #include #include #include -#include "bfLexer.h" -#include "bfParser.h" +#include "bfeLexer.h" +#include "bfeParser.h" #include "toBFListener.hpp" -// #include "bfBaseVisitor.h" using namespace antlr4; @@ -21,9 +20,9 @@ int main(int argc, const char *argv[]) return 1; } ANTLRInputStream input(stream); - bfLexer lexer(&input); + bfeLexer lexer(&input); CommonTokenStream tokens(&lexer); - bfParser parser(&tokens); + bfeParser parser(&tokens); tree::ParseTree *tree = parser.program(); toBFListener listener; diff --git a/src/toBFListener.cpp b/src/toBFListener.cpp index 92b075e..8b6be9d 100644 --- a/src/toBFListener.cpp +++ b/src/toBFListener.cpp @@ -1,41 +1,40 @@ -#pragma once -#include "bfParser.h" -#include "bfBaseListener.h" +#include "bfeParser.h" +#include "bfeBaseListener.h" #include "toBFListener.hpp" // #include "bfBaseVisitor.h" using namespace antlr4; -void toBFListener::enterProgram(bfParser::ProgramContext *ctx) +void toBFListener::enterProgram(bfeParser::ProgramContext *ctx) { printStack.push_back(""); } -void toBFListener::exitProgram(bfParser::ProgramContext *ctx) +void toBFListener::exitProgram(bfeParser::ProgramContext *ctx) { std::cout << printStack.front() << std::endl; } -void toBFListener::enterPtrIncr(bfParser::PtrIncrContext *ctx) +void toBFListener::enterPtrIncr(bfeParser::PtrIncrContext *ctx) { printStack.back() += "+"; } -void toBFListener::enterPtrDecr(bfParser::PtrDecrContext *ctx) +void toBFListener::enterPtrDecr(bfeParser::PtrDecrContext *ctx) { printStack.back() += ("-"); } -void toBFListener::enterPtrLeft(bfParser::PtrLeftContext *ctx) +void toBFListener::enterPtrLeft(bfeParser::PtrLeftContext *ctx) { printStack.back() += ("<"); } -void toBFListener::enterPtrRight(bfParser::PtrRightContext *ctx) +void toBFListener::enterPtrRight(bfeParser::PtrRightContext *ctx) { printStack.back() += (">"); } -void toBFListener::enterNumberedStmt(bfParser::NumberedStmtContext *ctx) +void toBFListener::enterNumberedStmt(bfeParser::NumberedStmtContext *ctx) { printStack.push_back(""); } -void toBFListener::exitNumberedStmt(bfParser::NumberedStmtContext *ctx) +void toBFListener::exitNumberedStmt(bfeParser::NumberedStmtContext *ctx) { std::string s = printStack.back(); printStack.pop_back(); @@ -45,18 +44,18 @@ void toBFListener::exitNumberedStmt(bfParser::NumberedStmtContext *ctx) printStack.back() += s; } } -void toBFListener::enterLoopStmt(bfParser::LoopStmtContext *ctx){ +void toBFListener::enterLoopStmt(bfeParser::LoopStmtContext *ctx){ printStack.push_back(""); } -void toBFListener::exitLoopStmt(bfParser::LoopStmtContext *ctx){ +void toBFListener::exitLoopStmt(bfeParser::LoopStmtContext *ctx){ std::string s = printStack.back(); printStack.pop_back(); printStack.back()+= "["+s+"]"; } -void toBFListener::enterGroupedStmt(bfParser::GroupedStmtContext *ctx){ +void toBFListener::enterGroupedStmt(bfeParser::GroupedStmtContext *ctx){ printStack.push_back(""); } -void toBFListener::exitGroupedStmt(bfParser::GroupedStmtContext *ctx){ +void toBFListener::exitGroupedStmt(bfeParser::GroupedStmtContext *ctx){ std::string s = printStack.back(); printStack.pop_back(); printStack.back()+=(s);