aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 63d0eb250d3a986730cafc95d0aada43a9896151 (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
use std::io::{ stdin };
use std::f64;

mod lex;
use crate::lex::*;

mod parse;
use crate::parse::*;

fn main() {
    loop {
        let mut input = String::new();
        stdin().read_line(&mut input).unwrap();

        let input = input.trim();
        let input = input.replace(" ", "");

        if input == "exit" {
            return
        }

        let lexed = lexer(&input[..]);
        let postfixed = to_postfix(lexed.unwrap());
        let evaled = eval_postfix(postfixed.unwrap());
        println!("ans: {}", evaled.unwrap());
        println!();
    }
}