Introducing execution(beta)

This commit is contained in:
2020-10-01 19:33:47 +05:30
parent 6b37f3987b
commit 2b17338a65
7 changed files with 160 additions and 9 deletions

57
src/executeBFE.cpp Normal file
View File

@@ -0,0 +1,57 @@
#include<iostream>
#include<vector>
#include<string>
#include <antlr4-common.h>
#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;i<num;i++){
ctx->stmt()->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<<memory[pointer];
return Any();
}
Any executeBGE::visitLoopStmt(bfeParser::LoopStmtContext *ctx){
while(memory[pointer]){
ctx->statements()->accept(this);
}
return Any();
}

View File

@@ -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;
}