Remove memory allocation bug
This commit is contained in:
31
.vscode/launch.json
vendored
31
.vscode/launch.json
vendored
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -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
1
samples/testmem.bfe
Normal file
@@ -0,0 +1 @@
|
||||
(+65.>)65536
|
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user