From 87ebe6ce99e798f3b7733647553c6c0f08f42153 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Sun, 24 Feb 2019 11:51:53 +0530 Subject: init --- .gitignore | 1 + Cargo.lock | 4 ++++ Cargo.toml | 7 +++++++ src/main.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..fc0c3b9 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "tokenizer" +version = "0.1.0" + diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..cac6e66 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "tokenizer" +version = "0.1.0" +authors = ["NerdyPepper "] +edition = "2018" + +[dependencies] 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