Skip to content

Commit 808b573

Browse files
committed
add log
1 parent 85d0d25 commit 808b573

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9+
log = "0.4.20"

src/lang/tokenizer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub enum Operator {
4646
Multiply,
4747
Divide,
4848
Exponent,
49+
Log,
4950
Factorial,
5051
None,
5152
}
@@ -64,6 +65,7 @@ impl Operator {
6465
}
6566
}
6667
Operator::Exponent => Ok(a.powf(b)),
68+
Operator::Log => Ok(a.log(b)),
6769
Operator::Factorial => Err("Factorials not supported for now".into()), //TODO
6870
Operator::None => Err("Inter: can't be none".into()) //TODO
6971
}
@@ -75,7 +77,7 @@ impl Operator {
7577

7678
fn priority(&self) -> i32 {
7779
match self {
78-
Operator::Exponent => 3,
80+
Operator::Exponent | Operator::Log => 3,
7981
Operator::Multiply | Operator::Divide => 2,
8082
Operator::Plus | Operator::Minus => 1,
8183
Operator::None => 4,
@@ -194,6 +196,7 @@ fn tokenize_special(name: String) -> Result<Token, String> {
194196
"*" => Token::Operator(Operator::Multiply),
195197
"/" => Token::Operator(Operator::Divide),
196198
"**" | "^" => Token::Operator(Operator::Exponent),
199+
"//" => Token::Operator(Operator::Log),
197200

198201
"==" => Token::Compare(Compare::Equal),
199202
"<" => Token::Compare(Compare::LessThan),

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod lang;
99

1010
fn main() {
1111
// Initiate heap memory
12-
let mut memory:HashMap<String, f64> =HashMap::new();
12+
let mut memory:HashMap<String, f64> = HashMap::new();
1313

1414
println!("Malors = Mathematic Logic from Rust.simplify()");
1515
// Get the command-line arguments

0 commit comments

Comments
 (0)