Browse Source

Add instructions enum

master
garritfra 4 years ago
parent
commit
20373d793d
  1. 22
      src/instructions.rs
  2. 2
      src/lexer.rs
  3. 4
      src/main.rs
  4. 11
      src/opcodes.rs

22
src/instructions.rs

@ -0,0 +1,22 @@
#[derive(Debug, Clone)]
pub enum OpCode {
Increment,
Decrement,
MoveRight,
MoveLeft,
Print,
Read,
LoopStart,
LoopEnd,
}
#[derive(Debug, Clone)]
pub enum Instruction {
Increment,
Decrement,
MoveRight,
MoveLeft,
Print,
Read,
Loop(Vec<OpCode>),
}

2
src/lexer.rs

@ -1,4 +1,4 @@
use crate::opcodes::OpCode;
use crate::instructions::OpCode;
pub fn lex(input: &str) -> Vec<OpCode> {
let mut tokens: Vec<OpCode> = Vec::new();

4
src/main.rs

@ -1,6 +1,6 @@
mod instructions;
mod lexer;
mod opcodes;
use opcodes::OpCode;
use instructions::OpCode;
fn main() {
let tokens: Vec<OpCode> = lexer::lex("++++++ [ > ++++++++++ < - ] > +++++ .");

11
src/opcodes.rs

@ -1,11 +0,0 @@
#[derive(Debug)]
pub enum OpCode {
Increment,
Decrement,
MoveRight,
MoveLeft,
Print,
Read,
LoopStart,
LoopEnd,
}
Loading…
Cancel
Save