feat: implemented application

This commit is contained in:
Yandrik 2021-11-29 23:35:54 +01:00
parent 3cc81812e6
commit 3240a28d7f
2 changed files with 19 additions and 3 deletions

View File

@ -1,7 +1,9 @@
pub mod lexer; mod lexer;
pub mod errors;
mod parser; mod parser;
pub use lexer::errors as lexer_errors;
pub use parser::errors as parser_errors;
pub fn calculate(expression: &str) -> Result<f64, parser::errors::ParserErrors> { pub fn calculate(expression: &str) -> Result<f64, parser::errors::ParserErrors> {
Ok(parser::parse(lexer::Lexer::new(expression))?) Ok(parser::parse(lexer::Lexer::new(expression))?)
} }

View File

@ -1,7 +1,21 @@
use s5_cb_calculator::lexer::Lexer; use std::io;
use std::io::Write;
use s5_cb_calculator::calculate;
fn main() { fn main() {
println!("Hi there! Welcome to OverComplicatedCalculator v1.0!"); println!("Hi there! Welcome to OverComplicatedCalculator v1.0!");
println!("To have OCC calculate something, just type it in!"); println!("To have OCC calculate something, just type it in!");
loop {
print!(" |> ");
io::stdout().flush().expect("Couldn't flush output!");
let mut expression = String::new();
io::stdin()
.read_line(&mut expression)
.expect("Couldn't read line, please try again later!");
match calculate(&expression.trim()) {
Ok(res) => println!("ans: {}", res),
Err(err) => println!("Expression couldn't be parsed: {:?}", err)
}
}
} }