2 Commits
0.1.0 ... 0.1.1

Author SHA1 Message Date
c55a1745a5 Remove memory allocation bug 2020-10-01 23:19:45 +05:30
a1c9e4894f Rearrange README 2020-10-01 22:13:11 +05:30
5 changed files with 61 additions and 25 deletions

31
.vscode/launch.json vendored
View File

@@ -10,7 +10,7 @@
"name": "Grammar - simple.bfe",
"input": "samples/simple.bfe",
"visualParseTree": true,
"grammar": "${workspaceFolder}/grammar/bf.g4"
"grammar": "${workspaceFolder}/grammar/bfe.g4"
},
{
"type": "antlr-debug",
@@ -18,7 +18,15 @@
"name": "Grammar - group.bfe",
"input": "samples/group.bfe",
"visualParseTree": true,
"grammar": "${workspaceFolder}/grammar/bf.g4"
"grammar": "${workspaceFolder}/grammar/bfe.g4"
},
{
"type": "antlr-debug",
"request": "launch",
"name": "Grammar - testmem.bfe",
"input": "samples/testmem.bfe",
"visualParseTree": true,
"grammar": "${workspaceFolder}/grammar/bfe.g4"
},
{
"name": "GDB - simple.bfe",
@@ -76,6 +84,25 @@
"ignoreFailures": true
}
]
},
{
"name": "GDB - testmem.bfe",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/main.out",
"args": ["samples/testmem.bfe"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

View File

@@ -20,22 +20,6 @@ Requires:
./bfc prog.bfe -t #Translate file to bf
```
## Setup oddities
1. Copy antlr4's cpp libs to `./libs/antlr4`. (Please take care that the include folder points straight to the files not to `antlr-runtime`)
2. Copy `antlr-4.8-complete.jar` to `./thirdparty/antlr`.
3. Generate parsers to `./libs/generated` or use VSCode with the ANTLR extension.
## Todo (Tentative)
- [ ] Grammar
- [X] Number shorthand
- [X] Loop statements
- [ ] Shorthand segments
- [X] Processing
- [X] Translate to bf
- [X] Execute results
## Syntax
**Basic**
@@ -65,3 +49,20 @@ Eg.
(+65>)3 //stores AAA
(<.)3 //prints AAA
```
## Setup oddities (dev)
1. Copy antlr4's cpp libs to `./libs/antlr4`. (Please take care that the include folder points straight to the files not to `antlr-runtime`)
2. Copy `antlr-4.8-complete.jar` to `./thirdparty/antlr`.
3. Generate parsers to `./libs/generated` or use VSCode with the ANTLR extension.
## Todo (Tentative)
- [ ] Grammar
- [X] Number shorthand
- [X] Loop statements
- [ ] Shorthand segments
- [X] Processing
- [X] Translate to bf
- [X] Execute results

View File

@@ -9,11 +9,11 @@ using namespace antlr4;
using namespace antlrcpp;
// using namespace std;
class executeBGE: public bfeBaseVisitor{
private:
protected:
std::vector<char> memory;
int pointer=0;
public:
executeBGE() : bfeBaseVisitor(),memory(100) {
executeBGE() : bfeBaseVisitor(),memory(1) {
}
// Any visitProgram(bfeParser::ProgramContext*) override;
Any visitNumberedStmt(bfeParser::NumberedStmtContext*) override;

1
samples/testmem.bfe Normal file
View File

@@ -0,0 +1 @@
(+65.>)65536

View File

@@ -20,9 +20,6 @@ Any executeBGE::visitNumberedStmt(bfeParser::NumberedStmtContext *ctx){
}
Any executeBGE::visitPtrIncr(bfeParser::PtrIncrContext *ctx){
if(memory.size()<pointer){
memory.push_back(0);
}
memory[pointer]++;
return Any();
}
@@ -33,13 +30,23 @@ Any executeBGE::visitPtrDecr(bfeParser::PtrDecrContext *ctx){
}
Any executeBGE::visitPtrRight(bfeParser::PtrRightContext *ctx){
// too much -> throw this program out
if(memory.max_size()==memory.size()){
throw (std::string("Max Size Reached ")+to_string(memory.capacity()));
}
// its about to be incremented -> need to increase
if(memory.size()==pointer+1){
memory.push_back(0);
}
pointer++;
return Any();
}
Any executeBGE::visitPtrLeft(bfeParser::PtrLeftContext *ctx){
if(pointer==0) throw std::string("Decrement below zero");
if(pointer==0){
throw std::string("Decrement below zero");
}
pointer--;
return Any();
}