Fix BF segfault
This commit is contained in:
parent
5f723f1774
commit
f4bba7dd5e
|
@ -35,7 +35,7 @@ void Generator::run() {
|
|||
while (!lbrackets.empty())
|
||||
lbrackets.pop();
|
||||
|
||||
for(int instruct = 0; instruct < program.size(); instruct++) {
|
||||
for (std::size_t instruct = 0; instruct < program.size(); instruct++) {
|
||||
|
||||
switch(program[instruct]) {
|
||||
case Instruction::EMPTY: break;
|
||||
|
|
|
@ -79,6 +79,8 @@ Parser::Token Parser::lex() {
|
|||
//std::cout << "PARSING: found RBRACKET" << (int)Instruction::RBRACKET << std::endl;
|
||||
return Token{ bfParser_Symbol::T_RBRACKET, std::move(p) };
|
||||
}
|
||||
default:
|
||||
return Token { bfParser_Symbol::T_EOF, nullptr };
|
||||
}
|
||||
} catch(BfLexer::NoMoreTokens) {
|
||||
return Token{ bfParser_Symbol::T_EOF, nullptr };
|
||||
|
@ -87,15 +89,13 @@ Parser::Token Parser::lex() {
|
|||
|
||||
std::unique_ptr<std::deque<Instruction>> Parser::reduce_PROGRAM(std::deque<Token> subparts) {
|
||||
// <program> ::= <instruction> <program>
|
||||
if (subparts[1].value == nullptr)
|
||||
return std::move(subparts[0].value);
|
||||
for(auto& instr : *(subparts[1].value))
|
||||
subparts[0].value->push_back(instr);
|
||||
return std::move(subparts[0].value);
|
||||
}
|
||||
std::unique_ptr<std::deque<Instruction>> Parser::reduce_EMPTY(std::deque<Token> subparts) {
|
||||
std::unique_ptr<std::deque<Instruction>> Parser::reduce_EMPTY(std::deque<Token>) {
|
||||
// <program> ::=
|
||||
return nullptr;
|
||||
return std::make_unique<std::deque<Instruction>>();
|
||||
}
|
||||
std::unique_ptr<std::deque<Instruction>> Parser::reduce_OPERATION(std::deque<Token> subparts) {
|
||||
// <instruction> ::= "PLUS" | "MINUS" | ... | "COMMA"
|
||||
|
|
Loading…
Reference in New Issue