diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index 78a05b0..aaf285d 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | use std::io::{ stdin, stdout }; | ||
2 | |||
1 | #[derive(Debug, Copy, Clone, PartialEq)] | 3 | #[derive(Debug, Copy, Clone, PartialEq)] |
2 | pub struct Operator { | 4 | pub struct Operator { |
3 | token: char, | 5 | token: char, |
@@ -31,14 +33,22 @@ impl Operator { | |||
31 | } | 33 | } |
32 | 34 | ||
33 | fn main() { | 35 | fn main() { |
34 | let input = "1 + 5 * 6 + 2"; | 36 | loop { |
35 | println!("{}", input); | 37 | let mut input = String::new(); |
36 | let input = input.replace(" ", ""); | 38 | stdin().read_line(&mut input).unwrap(); |
37 | let lexed = lexer(&input); | 39 | |
38 | let postfixed = to_postfix(lexed.unwrap()); | 40 | let input = input.trim(); |
39 | let evaled = eval_postfix(postfixed.unwrap()); | 41 | let input = input.replace(" ", ""); |
40 | 42 | ||
41 | println!("{:?}", evaled); | 43 | if input == "exit" { |
44 | return | ||
45 | } | ||
46 | |||
47 | let lexed = lexer(&input[..]); | ||
48 | let postfixed = to_postfix(lexed.unwrap()); | ||
49 | let evaled = eval_postfix(postfixed.unwrap()); | ||
50 | println!("{}", evaled.unwrap()); | ||
51 | } | ||
42 | } | 52 | } |
43 | 53 | ||
44 | fn lexer(input: &str) -> Result<Vec<Token>, String> { | 54 | fn lexer(input: &str) -> Result<Vec<Token>, String> { |