pub enum AstExpr {
Constant(Real),
Variable(String),
Function {
name: String,
args: Vec<AstExpr>,
},
Array {
name: String,
index: Box<AstExpr>,
},
Attribute {
base: String,
attr: String,
},
}
Expand description
Abstract Syntax Tree (AST) node representing an expression.
The AST is the core data structure used for representing parsed expressions. Each variant of this enum represents a different type of expression node, forming a tree structure that can be evaluated to produce a result.
Variants§
Constant(Real)
A literal numerical value.
Examples: 3.14
, 42
, -1.5
Variable(String)
A named variable reference.
Examples: x
, temperature
, result
Function
A function call with a name and list of argument expressions.
Examples: sin(x)
, max(a, b)
, sqrt(x*x + y*y)
Fields
Array
An array element access.
Examples: array[0]
, values[i+1]
Attribute
An attribute access on an object.
Examples: point.x
, settings.value
Implementations§
Source§impl AstExpr
impl AstExpr
Sourcepub fn pow(self, exp: Real) -> Real
pub fn pow(self, exp: Real) -> Real
Helper method that raises a constant expression to a power.
This is primarily used in testing to evaluate power operations on constants. For non-constant expressions, it returns 0.0 as a default value.
§Parameters
exp
- The exponent to raise the constant to
§Returns
The constant raised to the given power, or 0.0 for non-constant expressions