Add exponentation operator
+ Add hat token + Add exponentation operator Implements #3
This commit is contained in:
parent
c631171ff0
commit
93e8d867b4
@ -105,7 +105,7 @@ Supported binary operators:
|
||||
| / | 100 | Division | | \>= | 80 | Greater than or equal |
|
||||
| % | 100 | Modulo | | == | 80 | Equal |
|
||||
| && | 75 | Logical and | | != | 80 | Not equal |
|
||||
| || | 70 | Logical or | | | |
|
||||
| || | 70 | Logical or | ^ | 120 | Exponentation |
|
||||
|
||||
Supported unary operators:
|
||||
|
||||
|
@ -94,7 +94,7 @@
|
||||
//! | / | 100 | Division | | \>= | 80 | Greater than or equal |
|
||||
//! | % | 100 | Modulo | | == | 80 | Equal |
|
||||
//! | && | 75 | Logical and | | != | 80 | Not equal |
|
||||
//! | || | 70 | Logical or | | | |
|
||||
//! | || | 70 | Logical or | ^ | 120 | Exponentation |
|
||||
//!
|
||||
//! Supported unary operators:
|
||||
//!
|
||||
|
@ -9,6 +9,7 @@ pub enum Token {
|
||||
Star,
|
||||
Slash,
|
||||
Percent,
|
||||
Hat,
|
||||
|
||||
// Logic
|
||||
Eq,
|
||||
@ -56,6 +57,7 @@ fn char_to_partial_token(c: char) -> PartialToken {
|
||||
'*' => PartialToken::Token(Token::Star),
|
||||
'/' => PartialToken::Token(Token::Slash),
|
||||
'%' => PartialToken::Token(Token::Percent),
|
||||
'^' => PartialToken::Token(Token::Hat),
|
||||
|
||||
'=' => PartialToken::Eq,
|
||||
'!' => PartialToken::ExclamationMark,
|
||||
@ -88,6 +90,7 @@ impl Token {
|
||||
Token::Star => false,
|
||||
Token::Slash => false,
|
||||
Token::Percent => false,
|
||||
Token::Hat => false,
|
||||
|
||||
Token::Eq => false,
|
||||
Token::Neq => false,
|
||||
@ -119,6 +122,7 @@ impl Token {
|
||||
Token::Star => false,
|
||||
Token::Slash => false,
|
||||
Token::Percent => false,
|
||||
Token::Hat => false,
|
||||
|
||||
Token::Eq => false,
|
||||
Token::Neq => false,
|
||||
|
@ -101,6 +101,7 @@ pub fn tokens_to_operator_tree(tokens: Vec<Token>) -> Result<Node, Error> {
|
||||
Token::Star => Some(Node::new(Mul)),
|
||||
Token::Slash => Some(Node::new(Div)),
|
||||
Token::Percent => Some(Node::new(Mod)),
|
||||
Token::Hat => Some(Node::new(Exp)),
|
||||
|
||||
Token::Eq => Some(Node::new(Eq)),
|
||||
Token::Neq => Some(Node::new(Neq)),
|
||||
|
Loading…
Reference in New Issue
Block a user