feat: implemented application
This commit is contained in:
parent
3cc81812e6
commit
3240a28d7f
@ -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))?)
|
||||||
}
|
}
|
||||||
|
16
src/main.rs
16
src/main.rs
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user