diff --git a/src/executor.rs b/src/executor.rs index 4c1febf..1a5fcf9 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -40,6 +40,39 @@ impl LispState { } }); + add_function(&mut table, "sub", |x| { + if x.len() != 2 { + return vec![LispValue::Nil] + } + + if let (LispValue::Integer(lhs), LispValue::Integer(rhs)) = (&x[0], &x[1]) { + return vec![LispValue::Integer(lhs - rhs)]; + } + vec![LispValue::Nil] + }); + + add_function(&mut table, "mul", |x| { + if x.len() != 2 { + return vec![LispValue::Nil] + } + + if let (LispValue::Integer(lhs), LispValue::Integer(rhs)) = (&x[0], &x[1]) { + return vec![LispValue::Integer(lhs * rhs)]; + } + vec![LispValue::Nil] + }); + + add_function(&mut table, "div", |x| { + if x.len() != 2 { + return vec![LispValue::Nil] + } + + if let (LispValue::Integer(lhs), LispValue::Integer(rhs)) = (&x[0], &x[1]) { + return vec![LispValue::Integer(lhs / rhs)]; + } + vec![LispValue::Nil] + }); + LispState { table } diff --git a/src/main.rs b/src/main.rs index 802ed59..3e1bf0c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,6 @@ fn main() { Vec::new() } }; - println!("{:?}", tokens); let instructions = parse(tokens); let state = LispState::new(); diff --git a/src/parser.rs b/src/parser.rs index 77d4745..4a903a1 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -112,7 +112,6 @@ fn parse_exp(tokens: Vec) -> Vec { Token::CloseParen => { panic!("Unexpected closing parenthesis"); }, - _ => todo!() } i += 1; diff --git a/src/test.lisp b/src/test.lisp index d7318cb..bb4be9e 100644 --- a/src/test.lisp +++ b/src/test.lisp @@ -1,3 +1,3 @@ ; This is a comment -(print (add 1333 12423)) \ No newline at end of file +(print (add 1 (mul (div 16 2) (mul 13 2)))) \ No newline at end of file diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 1236334..0ea24e1 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -107,7 +107,9 @@ impl Tokenizer { tokens.push(Token::Integer(self.storage.iter().collect::().parse().unwrap())); self.storage.clear(); } else { - self.storage.push(char); + if char != '_' { + self.storage.push(char); + } continue; } } @@ -166,7 +168,9 @@ impl Tokenizer { } else if c.is_numeric() || c == '_' { self.reading_num = true; self.storage.clear(); - self.storage.push(c); + if c != '_' { + self.storage.push(c); + } continue; } }