aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2019-02-24 06:21:53 +0000
committerNerdyPepper <[email protected]>2019-02-24 06:21:53 +0000
commit87ebe6ce99e798f3b7733647553c6c0f08f42153 (patch)
treee1904496bf102f03a193d09de073150095d8dad8 /src
init
Diffstat (limited to 'src')
-rw-r--r--src/main.rs44
1 files changed, 44 insertions, 0 deletions
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 @@
1use std::str;
2
3struct Token {
4 kind: String,
5 val: String,
6}
7
8fn 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
39fn is_operator(x: char) -> bool {
40 match x {
41 '+' | '-' | '/' | '*' | '^' => true,
42 _ => false
43 }
44}