From a51680da08e397018224197ac6539535f7bb4dd3 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 19 Mar 2019 11:03:34 +0200 Subject: [PATCH] Add precedences to operators in docs --- README.md | 51 ++++++++++++++++++++++++++++++++++++--------------- src/lib.rs | 51 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 72 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index e432393..7306427 100644 --- a/README.md +++ b/README.md @@ -11,23 +11,44 @@ Evalexpr is a powerful arithmetic and boolean expression evaluator. ## Features + ### Operators + Supported binary operators: - | Operator | Description | - |----------|-------------| - | + | Sum | - | - | Difference | - | * | Product | - | / | Division | - | % | Modulo | - | < | Lower than | - | \> | Greater than | - | <= | Lower than or equal | - | \>= | Greater than or equal | - | == | Equal | - | != | Not equal | - | && | Logical and | - | || | Logical or | + | Operator | Precedence | Description | | Operator | Precedence | Description | + |----------|------------|-------------|---|----------|------------|-------------| + | + | 95 | Sum | | < | 80 | Lower than | + | - | 95 | Difference | | \> | 80 | Greater than | + | * | 100 | Product | | <= | 80 | Lower than or equal | + | / | 100 | Division | | \>= | 80 | Greater than or equal | + | % | 100 | Modulo | | == | 80 | Equal | + | && | 75 | Logical and | | != | 80 | Not equal | + | || | 70 | Logical or | | | | + + Supported unary operators: + + | Operator | Precedence | Description | + |----------|------------|-------------| + | - | 110 | Negation | + | ! | 110 | Logical not | + + ### Values + + Operators take values as arguments and produce values as results. + Values can be boolean, integer or floating point numbers. + Strings are supported as well, but there are no operations defined for them yet. + + Integers are internally represented as `i64`, and floating point numbers are represented as `f64`. + Operators that take numbers as arguments can either take integers or floating point numbers. + If one of the arguments is a floating point number, all others are converted to floating point numbers as well, and the resulting value is a floating point number as well. + Otherwise, the result is an integer. + + ### Variables + + + + + Supported binary operators: `!` `!=` `""` `''` `()` `[]` `,` `>` `<` `>=` `<=` `==` `+` unary/binary `-` `*` `/` `%` `&&` `||` `n..m`. diff --git a/src/lib.rs b/src/lib.rs index 2f8c18e..dff4154 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,23 +1,44 @@ //! //! ## Features //! +//! ### Operators +//! //! Supported binary operators: //! -//! | Operator | Description | -//! |----------|-------------| -//! | + | Sum | -//! | - | Difference | -//! | * | Product | -//! | / | Division | -//! | % | Modulo | -//! | < | Lower than | -//! | > | Greater than | -//! | <= | Lower than or equal | -//! | >= | Greater than or equal | -//! | == | Equal | -//! | != | Not equal | -//! | && | Logical and | -//! | || | Logical or | +//! | Operator | Precedence | Description | | Operator | Precedence | Description | +//! |----------|------------|-------------|---|----------|------------|-------------| +//! | + | 95 | Sum | | < | 80 | Lower than | +//! | - | 95 | Difference | | \> | 80 | Greater than | +//! | * | 100 | Product | | <= | 80 | Lower than or equal | +//! | / | 100 | Division | | \>= | 80 | Greater than or equal | +//! | % | 100 | Modulo | | == | 80 | Equal | +//! | && | 75 | Logical and | | != | 80 | Not equal | +//! | || | 70 | Logical or | | | | +//! +//! Supported unary operators: +//! +//! | Operator | Precedence | Description | +//! |----------|------------|-------------| +//! | - | 110 | Negation | +//! | ! | 110 | Logical not | +//! +//! ### Values +//! +//! Operators take values as arguments and produce values as results. +//! Values can be boolean, integer or floating point numbers. +//! Strings are supported as well, but there are no operations defined for them yet. +//! +//! Integers are internally represented as `i64`, and floating point numbers are represented as `f64`. +//! Operators that take numbers as arguments can either take integers or floating point numbers. +//! If one of the arguments is a floating point number, all others are converted to floating point numbers as well, and the resulting value is a floating point number as well. +//! Otherwise, the result is an integer. +//! +//! ### Variables +//! +//! +//! +//! +//! //! //!Supported binary operators: `!` `!=` `""` `''` `()` `[]` `,` `>` `<` `>=` `<=` `==` //!`+` unary/binary `-` `*` `/` `%` `&&` `||` `n..m`.