diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Cargo.lock | 4 | ||||
-rw-r--r-- | Cargo.toml | 7 | ||||
-rw-r--r-- | src/main.rs | 44 |
4 files changed, 56 insertions, 0 deletions
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 @@ | |||
1 | [[package]] | ||
2 | name = "tokenizer" | ||
3 | version = "0.1.0" | ||
4 | |||
diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..cac6e66 --- /dev/null +++ b/Cargo.toml | |||
@@ -0,0 +1,7 @@ | |||
1 | [package] | ||
2 | name = "tokenizer" | ||
3 | version = "0.1.0" | ||
4 | authors = ["NerdyPepper <[email protected]>"] | ||
5 | edition = "2018" | ||
6 | |||
7 | [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 @@ | |||
1 | use std::str; | ||
2 | |||
3 | struct Token { | ||
4 | kind: String, | ||
5 | val: String, | ||
6 | } | ||
7 | |||
8 | fn main() { | ||
9 | let input: &str = "2y + 11 + sin(5)"; | ||
10 | let input = input.replace(" ", ""); | ||
11 | println!("{}", input); | ||
12 | |||
13 | let mut num_vec: Vec<char> = vec![]; | ||
14 | let mut char_vec: Vec<char> = vec![]; | ||
15 | |||
16 | let mut result: Vec<Token> = vec![]; | ||
17 | |||
18 | for letter in input.chars() { | ||
19 | if letter.is_digit(10) { | ||
20 | num_vec.push(letter); | ||
21 | } else if letter == '.' { | ||
22 | num_vec.push(letter); | ||
23 | } else if letter.is_alphabetic() { | ||
24 | if num_vec.len() > 0 { | ||
25 | let token = Token { | ||
26 | kind: "Literal".into(), | ||
27 | val: num_vec.iter().collect::<String>() | ||
28 | }; | ||
29 | result.push(token); | ||
30 | char_vec.push(letter); | ||
31 | } | ||
32 | } else if is_operator(letter) { | ||
33 | |||
34 | } | ||
35 | } | ||
36 | |||
37 | } | ||
38 | |||
39 | fn is_operator(x: char) -> bool { | ||
40 | match x { | ||
41 | '+' | '-' | '/' | '*' | '^' => true, | ||
42 | _ => false | ||
43 | } | ||
44 | } | ||