src/emath/model

Types

EMathFn = proc (args: seq[float]): float {.noSideEffect.}
EMathFnLookup = Table[string, EMathFn]
EMathNode {.acyclic.} = ref object
  children*: seq[EMathNode]
  isFinal*: bool             ## used for parsing and validity check
  case kind*: EMathNodeKind
  of emnkLit:
      value*: float

  of emnkCall, emnkVar:
      ident*: string

  of emnkPrefix, emnkPostfix, emnkInfix:
      operator*: EMathOperator

  of emnkPar:
    nil
  
EMathNodeKind = enum
  emnkLit, emnkPar, emnkVar, emnkCall, emnkPrefix, emnkPostfix, emnkInfix
EMathOperator = enum
  emoPow = "^", emoMult = "*", emoDiv = "/", emoPlus = "+", emoMinus = "-",
  emoMod = "%", emoNotFact = "!", emoAnd = "&", emoOr = "|", emoLarger = ">",
  emoLargerEq = ">=", emoEq = "==", emoNotEq = "!=", emoAlmostEq = "~=",
  emoLessEq = "<=", emoLess = "<", emoAssign = "="
EMathToken = object
  slice*: Slice[int]
  case kind*: EMathTokenKind
  of emtkNumber:
      number*: float

  of emtkIdent:
      ident*: string

  of emtkOperator:
      operator*: EMathOperator

  else:
    nil
  
EMathTokenKind = enum
  emtkNumber, emtkOperator, emtkIdent, emtkOpenPar, emtkClosePar, emtkComma
EMathVarLookup = Table[string, float]

Procs

func inside(mn: EMathNode): EMathNode {....raises: [], tags: [].}
returns the inside value of a parenthesis/prefix/postfix
func left(mn: EMathNode): EMathNode {....raises: [], tags: [].}
returns the left side of an infix operator
func priority(mo: EMathOperator): int {....raises: [], tags: [].}
func right(mn: EMathNode): EMathNode {....raises: [], tags: [].}
returns the right side of an infix operator