blob: 0a13e3e74f2bc5a743f83e30562f3800d836f382 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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<char> = vec![];
let mut char_vec: Vec<char> = vec![];
let mut result: Vec<Token> = 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::<String>()
};
result.push(token);
char_vec.push(letter);
}
} else if is_operator(letter) {
}
}
}
fn is_operator(x: char) -> bool {
match x {
'+' | '-' | '/' | '*' | '^' => true,
_ => false
}
}
|