Change grammar name

This commit is contained in:
2020-10-01 13:14:57 +05:30
parent 63e8acf141
commit 6b37f3987b
7 changed files with 47 additions and 47 deletions

View File

@@ -8,6 +8,7 @@
"outputDir": "../lib/generated" "outputDir": "../lib/generated"
}, },
"files.associations": { "files.associations": {
"ostream": "cpp" "ostream": "cpp",
"iostream": "cpp"
} }
} }

View File

@@ -10,12 +10,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
set(SOURCES set(SOURCES
src/main.cpp src/main.cpp
src/toBFListener.cpp src/toBFListener.cpp
lib/generated/bfLexer.cpp src/executeBFE.cpp
lib/generated/bfParser.cpp lib/generated/bfeLexer.cpp
lib/generated/bfBaseVisitor.cpp lib/generated/bfeParser.cpp
lib/generated/bfVisitor.cpp lib/generated/bfeBaseVisitor.cpp
lib/generated/bfBaseListener.cpp lib/generated/bfeVisitor.cpp
lib/generated/bfListener.cpp lib/generated/bfeBaseListener.cpp
lib/generated/bfeListener.cpp
) )
add_executable(main.out ${SOURCES}) add_executable(main.out ${SOURCES})

View File

@@ -19,7 +19,7 @@ An extension of a language that shall not be named
- [ ] Grammar - [ ] Grammar
- [X] Number shorthand - [X] Number shorthand
- [X] Loop statements - [X] Loop statements
- [ ] shorthand segments - [ ] Shorthand segments
- [ ] Processing - [ ] Processing
- [X] Print resultant .bf - [X] Translate to bf
- [ ] execute result - [ ] Execute result

View File

@@ -1,4 +1,4 @@
grammar bf; grammar bfe;
program program
: statements? EOF; : statements? EOF;

View File

@@ -1,25 +1,25 @@
#pragma once #pragma once
#include<string> #include<string>
#include "bfLexer.h" #include "bfeLexer.h"
#include "bfParser.h" #include "bfeParser.h"
#include "bfBaseListener.h" #include "bfeBaseListener.h"
class toBFListener : public bfBaseListener { class toBFListener : public bfeBaseListener {
protected: protected:
std::vector<std::string> printStack; std::vector<std::string> printStack;
public: public:
void enterProgram(bfParser::ProgramContext *ctx) override; void enterProgram(bfeParser::ProgramContext *ctx) override;
void exitProgram(bfParser::ProgramContext *ctx) override ; void exitProgram(bfeParser::ProgramContext *ctx) override ;
void enterPtrIncr(bfParser::PtrIncrContext *ctx) override; void enterPtrIncr(bfeParser::PtrIncrContext *ctx) override;
void enterPtrDecr(bfParser::PtrDecrContext *ctx) override; void enterPtrDecr(bfeParser::PtrDecrContext *ctx) override;
void enterPtrLeft(bfParser::PtrLeftContext *ctx) override; void enterPtrLeft(bfeParser::PtrLeftContext *ctx) override;
void enterPtrRight(bfParser::PtrRightContext *ctx) override; void enterPtrRight(bfeParser::PtrRightContext *ctx) override;
void enterNumberedStmt(bfParser::NumberedStmtContext *ctx) override; void enterNumberedStmt(bfeParser::NumberedStmtContext *ctx) override;
void exitNumberedStmt(bfParser::NumberedStmtContext *ctx) override; void exitNumberedStmt(bfeParser::NumberedStmtContext *ctx) override;
void enterLoopStmt(bfParser::LoopStmtContext *ctx) override; void enterLoopStmt(bfeParser::LoopStmtContext *ctx) override;
void exitLoopStmt(bfParser::LoopStmtContext *ctx) override; void exitLoopStmt(bfeParser::LoopStmtContext *ctx) override;
void enterGroupedStmt(bfParser::GroupedStmtContext *ctx) override; void enterGroupedStmt(bfeParser::GroupedStmtContext *ctx) override;
void exitGroupedStmt(bfParser::GroupedStmtContext *ctx) override; void exitGroupedStmt(bfeParser::GroupedStmtContext *ctx) override;
}; };

View File

@@ -2,11 +2,10 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <antlr4-common.h> #include <antlr4-common.h>
#include "bfLexer.h" #include "bfeLexer.h"
#include "bfParser.h" #include "bfeParser.h"
#include "toBFListener.hpp" #include "toBFListener.hpp"
// #include "bfBaseVisitor.h"
using namespace antlr4; using namespace antlr4;
@@ -21,9 +20,9 @@ int main(int argc, const char *argv[])
return 1; return 1;
} }
ANTLRInputStream input(stream); ANTLRInputStream input(stream);
bfLexer lexer(&input); bfeLexer lexer(&input);
CommonTokenStream tokens(&lexer); CommonTokenStream tokens(&lexer);
bfParser parser(&tokens); bfeParser parser(&tokens);
tree::ParseTree *tree = parser.program(); tree::ParseTree *tree = parser.program();
toBFListener listener; toBFListener listener;

View File

@@ -1,41 +1,40 @@
#pragma once #include "bfeParser.h"
#include "bfParser.h" #include "bfeBaseListener.h"
#include "bfBaseListener.h"
#include "toBFListener.hpp" #include "toBFListener.hpp"
// #include "bfBaseVisitor.h" // #include "bfBaseVisitor.h"
using namespace antlr4; using namespace antlr4;
void toBFListener::enterProgram(bfParser::ProgramContext *ctx) void toBFListener::enterProgram(bfeParser::ProgramContext *ctx)
{ {
printStack.push_back(""); printStack.push_back("");
} }
void toBFListener::exitProgram(bfParser::ProgramContext *ctx) void toBFListener::exitProgram(bfeParser::ProgramContext *ctx)
{ {
std::cout << printStack.front() << std::endl; std::cout << printStack.front() << std::endl;
} }
void toBFListener::enterPtrIncr(bfParser::PtrIncrContext *ctx) void toBFListener::enterPtrIncr(bfeParser::PtrIncrContext *ctx)
{ {
printStack.back() += "+"; printStack.back() += "+";
} }
void toBFListener::enterPtrDecr(bfParser::PtrDecrContext *ctx) void toBFListener::enterPtrDecr(bfeParser::PtrDecrContext *ctx)
{ {
printStack.back() += ("-"); printStack.back() += ("-");
} }
void toBFListener::enterPtrLeft(bfParser::PtrLeftContext *ctx) void toBFListener::enterPtrLeft(bfeParser::PtrLeftContext *ctx)
{ {
printStack.back() += ("<"); printStack.back() += ("<");
} }
void toBFListener::enterPtrRight(bfParser::PtrRightContext *ctx) void toBFListener::enterPtrRight(bfeParser::PtrRightContext *ctx)
{ {
printStack.back() += (">"); printStack.back() += (">");
} }
void toBFListener::enterNumberedStmt(bfParser::NumberedStmtContext *ctx) void toBFListener::enterNumberedStmt(bfeParser::NumberedStmtContext *ctx)
{ {
printStack.push_back(""); printStack.push_back("");
} }
void toBFListener::exitNumberedStmt(bfParser::NumberedStmtContext *ctx) void toBFListener::exitNumberedStmt(bfeParser::NumberedStmtContext *ctx)
{ {
std::string s = printStack.back(); std::string s = printStack.back();
printStack.pop_back(); printStack.pop_back();
@@ -45,18 +44,18 @@ void toBFListener::exitNumberedStmt(bfParser::NumberedStmtContext *ctx)
printStack.back() += s; printStack.back() += s;
} }
} }
void toBFListener::enterLoopStmt(bfParser::LoopStmtContext *ctx){ void toBFListener::enterLoopStmt(bfeParser::LoopStmtContext *ctx){
printStack.push_back(""); printStack.push_back("");
} }
void toBFListener::exitLoopStmt(bfParser::LoopStmtContext *ctx){ void toBFListener::exitLoopStmt(bfeParser::LoopStmtContext *ctx){
std::string s = printStack.back(); std::string s = printStack.back();
printStack.pop_back(); printStack.pop_back();
printStack.back()+= "["+s+"]"; printStack.back()+= "["+s+"]";
} }
void toBFListener::enterGroupedStmt(bfParser::GroupedStmtContext *ctx){ void toBFListener::enterGroupedStmt(bfeParser::GroupedStmtContext *ctx){
printStack.push_back(""); printStack.push_back("");
} }
void toBFListener::exitGroupedStmt(bfParser::GroupedStmtContext *ctx){ void toBFListener::exitGroupedStmt(bfeParser::GroupedStmtContext *ctx){
std::string s = printStack.back(); std::string s = printStack.back();
printStack.pop_back(); printStack.pop_back();
printStack.back()+=(s); printStack.back()+=(s);