Change grammar name
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -8,6 +8,7 @@
|
||||
"outputDir": "../lib/generated"
|
||||
},
|
||||
"files.associations": {
|
||||
"ostream": "cpp"
|
||||
"ostream": "cpp",
|
||||
"iostream": "cpp"
|
||||
}
|
||||
}
|
@@ -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})
|
||||
|
||||
|
@@ -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
|
||||
- [X] Translate to bf
|
||||
- [ ] Execute result
|
@@ -1,4 +1,4 @@
|
||||
grammar bf;
|
||||
grammar bfe;
|
||||
|
||||
program
|
||||
: statements? EOF;
|
@@ -1,25 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include<string>
|
||||
#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<std::string> 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;
|
||||
};
|
@@ -2,11 +2,10 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <antlr4-common.h>
|
||||
#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;
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user