a branflakes interpreter i used to play with c++
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

49 lines
1.0 KiB

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "brainfuck.hpp"
#include "error.hpp"
#include "lex.hpp"
void Lexer::printCode() {
std::cout << bf << std::endl;
}
std::vector<OpCode> Lexer::lexCode() {
std::vector<OpCode> v;
for (auto c : bf) {
switch(c) {
case '>':
v.push_back(OpCode::IncPtr);
break;
case '<':
v.push_back(OpCode::DecPtr);
break;
case '+':
v.push_back(OpCode::IncByte);
break;
case '-':
v.push_back(OpCode::DecByte);
break;
case '.':
v.push_back(OpCode::Write);
break;
case ',':
v.push_back(OpCode::Read);
break;
case '[':
v.push_back(OpCode::LoopBegin);
break;
case ']':
v.push_back(OpCode::LoopEnd);
break;
default:
break; // all undef characters are comments
}
}
return v;
}