-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6e225b
commit 75f7125
Showing
9 changed files
with
258 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include<string> | ||
#include "bfeLexer.h" | ||
#include "bfeParser.h" | ||
#include "bfeBaseListener.h" | ||
|
||
|
||
class toCPPListener : public bfeBaseListener { | ||
protected: | ||
std::vector<std::string> printStack; | ||
public: | ||
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; | ||
void enterOutputStmt(bfeParser::OutputStmtContext *ctx) override; | ||
void enterInputStmt(bfeParser::InputStmtContext *ctx) override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
>,<>>,>,<[->- | ||
>+<><<]+->>[-<<+>>] | ||
<+-><><<<[-+->-<+-<+>]< | ||
[->+<]><>>>>>><>++->>+->> | ||
>>>+[>><>>>[-]<[-<>-+]<<>[- | ||
+-]-++-+-< [-]<><<>[+ | ||
---+]<><< <<+-<<<<> | ||
-+<><<<> <+-<<[-> | ||
>>>>>>+ >>>>>-+ | ||
>+<<<>< < <><<<<< | ||
<<<<]>[ ->> >>><><> | ||
><>>+>> >>>>+ <<<<<>< | ||
<<<<+-< <<<]> [->>>>> | ||
>><>+ | ||
>>>>- | ||
+><>> | ||
+<<<< | ||
<<+-< | ||
<<<><<<< -+><] >>-++-+>+-+[<-] <[->> | ||
<>++-<<<]>>>> [-<<< +--+<<<<+>><>>> >>>]> | ||
[-<<-+<<<<<+<>> +->>> >>>]>[-<<<<><<< ><<+> | ||
>>>>>>]>>>>>><>>+ [-<<< <+--+<><+-<<<<< <[->> | ||
+>>+<<<<]+->[->>+>> +-+<< <<]>[-<<+>>]>[- <<+>> | ||
]+[[<>-]-++>[<-]<+-[ +-->< >><>-<<<]>>-+-> >>+>[ | ||
<-]<+-[- >+>[- <-]<[ >>[-< <-+-> | ||
]-<<[-> ><- >+->- +-<<< <]]<] | ||
>>-<<< < <+>[> <<-]< [>+-> | ||
[-+<<- >]<<[ <]]>- +-]>> | ||
>>><>> >><>+ ]-<<< >+-<< | ||
<>+>- ++[<- ]<[-+ >>+[< | ||
<<>-> -+]<< [>>>+ [<-+< | ||
<->>] <<<[< ]]]>- ]>>>> | ||
[-]<< <<<<< -+<>< <<<<< | ||
<[-]> >+>+[ <-]<[ ->>+< | ||
><<<] >+>[< -]<[> >[<<- | ||
>]<<[ <]]>- [+>>> >>>>< | ||
++-++ +++++ ++<<< <<<+> | ||
+-[<<> -]<[> >[<<- >]<<[ | ||
<]]>-[ ++>[< -]<[- >>-<< | ||
<]>>-> > +>>+> -[<-] <[<<[ | ||
->>>+<< ><< ]+->> >>>+> +[<>< | ||
-]<><[-> >+<<< ]<<-< ]<<<< +>[<- | ||
]<[>>[<<->]<<[<]]>-] >>+++ +++++[ -> +++++ | ||
+<]>[-<<<<+>>>>]>>> >>+>< >-+[<-]<[>> [<<-> | ||
]<<[<]]>-[++>[<-] <[->> -<<<]>>-<<< <<<<< | ||
+>+[<-]<[->>+<< <]>>> >>>>>+>[<- ]<[>> | ||
[<<->]<<[<]]> -]<<[ -]<<<<<+> [<-]< | ||
[>>[<<-> ]<<[< ]]>-]<< [.<] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "bfeParser.h" | ||
#include "bfeBaseListener.h" | ||
#include "toCPPListener.hpp" | ||
// #include "bfBaseVisitor.h" | ||
|
||
using namespace antlr4; | ||
|
||
void toCPPListener::enterProgram(bfeParser::ProgramContext *ctx) | ||
{ | ||
printStack.push_back("#include<iostream>\n#include<vector>\nusing namespace std;\nint main(){\nvector<char> vec(1000,0);int ptr = 0;\n"); | ||
} | ||
void toCPPListener::exitProgram(bfeParser::ProgramContext *ctx) | ||
{ | ||
std::cout << printStack.front() << "}\n"<< std::endl; | ||
} | ||
void toCPPListener::enterPtrIncr(bfeParser::PtrIncrContext *ctx) | ||
{ | ||
// printStack.back() += "+"; | ||
printStack.back()+= "vec[ptr]++;\n"; | ||
} | ||
void toCPPListener::enterPtrDecr(bfeParser::PtrDecrContext *ctx) | ||
{ | ||
// printStack.back() += ("-"); | ||
printStack.back()+= "vec[ptr]--;\n"; | ||
} | ||
void toCPPListener::enterPtrLeft(bfeParser::PtrLeftContext *ctx) | ||
{ | ||
// printStack.back() += ("<"); | ||
printStack.back() += ("ptr--;\n"); | ||
} | ||
void toCPPListener::enterPtrRight(bfeParser::PtrRightContext *ctx) | ||
{ | ||
|
||
printStack.back() += ("ptr++;\n"); | ||
} | ||
|
||
void toCPPListener::enterNumberedStmt(bfeParser::NumberedStmtContext *ctx) | ||
{ | ||
printStack.push_back(""); | ||
} | ||
void toCPPListener::exitNumberedStmt(bfeParser::NumberedStmtContext *ctx) | ||
{ | ||
std::string s = printStack.back(); | ||
printStack.pop_back(); | ||
int n = stoi(ctx->NUMBER()->getText()); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
printStack.back() += s; | ||
} | ||
} | ||
void toCPPListener::enterLoopStmt(bfeParser::LoopStmtContext *ctx){ | ||
printStack.push_back(""); | ||
} | ||
void toCPPListener::exitLoopStmt(bfeParser::LoopStmtContext *ctx){ | ||
std::string s = printStack.back(); | ||
printStack.pop_back(); | ||
printStack.back()+= "while(vec[ptr]){\n"+s+"}\n"; | ||
} | ||
|
||
void toCPPListener::enterOutputStmt(bfeParser::OutputStmtContext *ctx){ | ||
std::string s = printStack.back(); | ||
// printStack.pop_back(); | ||
printStack.back()+= "cout<<vec[ptr];\n"; | ||
} | ||
|
||
void toCPPListener::enterInputStmt(bfeParser::InputStmtContext *ctx){ | ||
// std::string s = printStack.back(); | ||
// printStack.pop_back(); | ||
printStack.back()+= "cin>>vec[ptr];\n"; | ||
} | ||
|
||
void toCPPListener::enterGroupedStmt(bfeParser::GroupedStmtContext *ctx){ | ||
printStack.push_back(""); | ||
} | ||
void toCPPListener::exitGroupedStmt(bfeParser::GroupedStmtContext *ctx){ | ||
std::string s = printStack.back(); | ||
printStack.pop_back(); | ||
printStack.back()+=(s); | ||
} |