From 87ebe6ce99e798f3b7733647553c6c0f08f42153 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Sun, 24 Feb 2019 11:51:53 +0530 Subject: init --- src/main.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main.rs (limited to 'src') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..0a13e3e --- /dev/null +++ b/src/main.rs @@ -0,0 +1,44 @@ +use std::str; + +struct Token { + kind: String, + val: String, +} + +fn main() { + let input: &str = "2y + 11 + sin(5)"; + let input = input.replace(" ", ""); + println!("{}", input); + + let mut num_vec: Vec = vec![]; + let mut char_vec: Vec = vec![]; + + let mut result: Vec = vec![]; + + for letter in input.chars() { + if letter.is_digit(10) { + num_vec.push(letter); + } else if letter == '.' { + num_vec.push(letter); + } else if letter.is_alphabetic() { + if num_vec.len() > 0 { + let token = Token { + kind: "Literal".into(), + val: num_vec.iter().collect::() + }; + result.push(token); + char_vec.push(letter); + } + } else if is_operator(letter) { + + } + } + +} + +fn is_operator(x: char) -> bool { + match x { + '+' | '-' | '/' | '*' | '^' => true, + _ => false + } +} -- cgit v1.2.3