JustBash.Arithmetic.Evaluator (JustBash v0.4.0)

View Source

Evaluates arithmetic expression AST nodes.

Takes parsed AST nodes and an environment (variable bindings), returns the computed integer value and updated environment.

Handles:

  • Arithmetic operations: +, -, , /, %, *
  • Comparison operations: <, <=, >, >=, ==, !=
  • Bitwise operations: &, |, ^, ~, <<, >>
  • Logical operations: &&, ||, !
  • Assignment operations: =, +=, -=, etc.
  • Pre/post increment/decrement: ++, --
  • Ternary conditional: ? :

Summary

Functions

Evaluate an arithmetic AST in the given environment. Returns {:ok, result, updated_env} or {:error, reason, env}.

Functions

evaluate(ast, env)

@spec evaluate(JustBash.AST.arith_expr(), map()) ::
  {:ok, integer(), map()} | {:error, :division_by_zero, map()}

Evaluate an arithmetic AST in the given environment. Returns {:ok, result, updated_env} or {:error, reason, env}.