mirror of https://git.sr.ht/~garritfra/rustfuck
garritfra
4 years ago
3 changed files with 39 additions and 1 deletions
@ -0,0 +1,20 @@
|
||||
use crate::opcodes::OpCode; |
||||
|
||||
pub fn lex(input: &str) -> Vec<OpCode> { |
||||
let mut tokens: Vec<OpCode> = Vec::new(); |
||||
for (_, character) in input.chars().enumerate() { |
||||
match character { |
||||
'+' => tokens.push(OpCode::Increment), |
||||
'-' => tokens.push(OpCode::Decrement), |
||||
'>' => tokens.push(OpCode::MoveRight), |
||||
'<' => tokens.push(OpCode::MoveLeft), |
||||
'.' => tokens.push(OpCode::Print), |
||||
',' => tokens.push(OpCode::Read), |
||||
'[' => tokens.push(OpCode::LoopStart), |
||||
']' => tokens.push(OpCode::LoopEnd), |
||||
_ => (), |
||||
} |
||||
} |
||||
|
||||
tokens |
||||
} |
@ -1,3 +1,10 @@
|
||||
mod lexer; |
||||
mod opcodes; |
||||
use opcodes::OpCode; |
||||
|
||||
fn main() { |
||||
println!("Hello, world!"); |
||||
let tokens: Vec<OpCode> = lexer::lex("++++++ [ > ++++++++++ < - ] > +++++ ."); |
||||
for token in tokens { |
||||
println!("{:?}", token); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue