From eeeaf894e020697585a329d7bbb679316d5447a2 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Mon, 21 Sep 2020 12:41:29 +0200 Subject: [PATCH] moved comment parsing to first pass, to save program space --- interpreter.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/interpreter.cpp b/interpreter.cpp index 4f3615c..1a340db 100644 --- a/interpreter.cpp +++ b/interpreter.cpp @@ -36,6 +36,8 @@ std::string interpreter::eval(std::istream& in, bool& done) { for (std::string line; std::getline(in, line); ++_pc) { if (line[0] == ':') { _labels.emplace(line.substr(1), _pc--); + } else if (line[0] == '#') { // check comment + _pc--; } else { _prog.push_back(line); } @@ -47,12 +49,6 @@ std::string interpreter::eval(std::istream& in, bool& done) { // fetch next instruction std::string code {_prog[_pc]}; - // check comment - if (code[0] == '#') { - _pc++; - continue; - } - // check literal int if (std::isdigit(code[0])) { _stack.push_back(code);