From 4d94a7ad5965d163c4a20585e1897636a9f27af7 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Tue, 9 Apr 2024 05:32:50 +0200 Subject: [PATCH] class and kind types removed --- operand-const.go | 20 +++++++++----------- operand-expr.go | 2 -- operand-func.go | 8 +++----- operand-list.go | 2 -- operand-selector-case.go | 2 -- operand-var.go | 6 +++--- operator-assign.go | 2 -- operator-bool.go | 14 ++++++-------- operator-but.go | 2 -- operator-coalesce.go | 8 +++----- operator-ctrl.go | 2 -- operator-fact.go | 2 -- operator-prod.go | 20 +++++++++----------- operator-rel.go | 32 +++++++++++++++----------------- operator-selector.go | 2 -- operator-sign.go | 8 +++----- operator-sum.go | 8 +++----- term.go | 37 ++----------------------------------- 18 files changed, 56 insertions(+), 121 deletions(-) diff --git a/operand-const.go b/operand-const.go index 96e12df..4cf8ac8 100644 --- a/operand-const.go +++ b/operand-const.go @@ -7,9 +7,9 @@ package expr // -------- bool const term func newBoolTerm(tk *Token) *term { return &term{ - tk: *tk, - class: classConst, - kind: kindBool, + tk: *tk, + // class: classConst, + // kind: kindBool, parent: nil, children: nil, position: posLeaf, @@ -22,8 +22,6 @@ func newBoolTerm(tk *Token) *term { func newIntegerTerm(tk *Token) *term { return &term{ tk: *tk, - class: classConst, - kind: kindInteger, parent: nil, children: nil, position: posLeaf, @@ -35,9 +33,9 @@ func newIntegerTerm(tk *Token) *term { // -------- float const term func newFloatTerm(tk *Token) *term { return &term{ - tk: *tk, - class: classConst, - kind: kindFloat, + tk: *tk, + // class: classConst, + // kind: kindFloat, parent: nil, children: nil, position: posLeaf, @@ -49,9 +47,9 @@ func newFloatTerm(tk *Token) *term { // -------- string const term func newStringTerm(tk *Token) *term { return &term{ - tk: *tk, - class: classConst, - kind: kindString, + tk: *tk, + // class: classConst, + // kind: kindString, parent: nil, children: nil, position: posLeaf, diff --git a/operand-expr.go b/operand-expr.go index e6a0a25..e619d63 100644 --- a/operand-expr.go +++ b/operand-expr.go @@ -10,8 +10,6 @@ import "fmt" func newExprTerm(tk *Token) *term { return &term{ tk: *tk, - class: classVar, - kind: kindUnknown, parent: nil, children: nil, position: posLeaf, diff --git a/operand-func.go b/operand-func.go index 7ad02ce..e609478 100644 --- a/operand-func.go +++ b/operand-func.go @@ -11,9 +11,9 @@ import ( // -------- function call term func newFuncCallTerm(tk *Token, args []*term) *term { return &term{ - tk: *tk, - class: classVar, - kind: kindUnknown, + tk: *tk, + // class: classVar, + // kind: kindUnknown, parent: nil, children: args, position: posLeaf, @@ -71,8 +71,6 @@ func exportFunc(ctx ExprContext, name string, info ExprFunc) { func newFuncDefTerm(tk *Token, args []*term) *term { return &term{ tk: *tk, - class: classVar, - kind: kindUnknown, parent: nil, children: args, // arg[0]=formal-param-list, arg[1]=*ast position: posLeaf, diff --git a/operand-list.go b/operand-list.go index 65e7e38..6d83a01 100644 --- a/operand-list.go +++ b/operand-list.go @@ -8,8 +8,6 @@ package expr func newListTerm(args []*term) *term { return &term{ tk: *NewToken(0, 0, SymList, "[]"), - class: classVar, - kind: kindUnknown, parent: nil, children: args, position: posLeaf, diff --git a/operand-selector-case.go b/operand-selector-case.go index b3b1a1b..801a385 100644 --- a/operand-selector-case.go +++ b/operand-selector-case.go @@ -17,8 +17,6 @@ func newSelectorCaseTerm(row, col int, filterList *term, caseExpr Expr) *term { tk := NewValueToken(row, col, SymSelectorCase, "", &selectorCase{filterList: filterList, caseExpr: caseExpr}) return &term{ tk: *tk, - class: classVar, - kind: kindUnknown, parent: nil, children: nil, position: posLeaf, diff --git a/operand-var.go b/operand-var.go index b8d6f4c..cbb58b3 100644 --- a/operand-var.go +++ b/operand-var.go @@ -9,9 +9,9 @@ import "fmt" // -------- variable term func newVarTerm(tk *Token) *term { return &term{ - tk: *tk, - class: classVar, - kind: kindUnknown, + tk: *tk, + // class: classVar, + // kind: kindUnknown, parent: nil, children: nil, position: posLeaf, diff --git a/operator-assign.go b/operator-assign.go index 6ba089b..b00d8ea 100644 --- a/operator-assign.go +++ b/operator-assign.go @@ -9,8 +9,6 @@ package expr func newAssignTerm(tk *Token) (inst *term) { return &term{ tk: *tk, - class: classOperator, - kind: kindUnknown, children: make([]*term, 0, 2), position: posInfix, priority: priAssign, diff --git a/operator-bool.go b/operator-bool.go index a26af68..d390e91 100644 --- a/operator-bool.go +++ b/operator-bool.go @@ -11,8 +11,6 @@ import "fmt" func newNotTerm(tk *Token) (inst *term) { return &term{ tk: *tk, - class: classOperator, - kind: kindBool, children: make([]*term, 0, 1), position: posPrefix, priority: priNot, @@ -39,9 +37,9 @@ func evalNot(ctx ExprContext, self *term) (v any, err error) { func newAndTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindBool, + tk: *tk, + // class: classOperator, + // kind: kindBool, children: make([]*term, 0, 2), position: posInfix, priority: priAnd, @@ -108,9 +106,9 @@ func evalAndWithShortcut(ctx ExprContext, self *term) (v any, err error) { func newOrTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindBool, + tk: *tk, + // class: classOperator, + // kind: kindBool, children: make([]*term, 0, 2), position: posInfix, priority: priOr, diff --git a/operator-but.go b/operator-but.go index 8ad0412..f145aab 100644 --- a/operator-but.go +++ b/operator-but.go @@ -9,8 +9,6 @@ package expr func newButTerm(tk *Token) (inst *term) { return &term{ tk: *tk, - class: classOperator, - kind: kindUnknown, children: make([]*term, 0, 2), position: posInfix, priority: priBut, diff --git a/operator-coalesce.go b/operator-coalesce.go index f285139..f2f2276 100644 --- a/operator-coalesce.go +++ b/operator-coalesce.go @@ -8,9 +8,9 @@ package expr func newNullCoalesceTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindUnknown, + tk: *tk, + // class: classOperator, + // kind: kindUnknown, children: make([]*term, 0, 2), position: posInfix, priority: priCoalesce, @@ -48,8 +48,6 @@ func evalNullCoalesce(ctx ExprContext, self *term) (v any, err error) { func newCoalesceAssignTerm(tk *Token) (inst *term) { return &term{ tk: *tk, - class: classOperator, - kind: kindUnknown, children: make([]*term, 0, 2), position: posInfix, priority: priCoalesce, diff --git a/operator-ctrl.go b/operator-ctrl.go index 7b8b93e..7efc2f0 100644 --- a/operator-ctrl.go +++ b/operator-ctrl.go @@ -9,8 +9,6 @@ package expr func newExportAllTerm(tk *Token) (inst *term) { return &term{ tk: *tk, - class: classOperator, - kind: kindUnknown, children: nil, position: posLeaf, priority: priValue, diff --git a/operator-fact.go b/operator-fact.go index 7bc5387..27584b6 100644 --- a/operator-fact.go +++ b/operator-fact.go @@ -11,8 +11,6 @@ import "fmt" func newFactTerm(tk *Token) (inst *term) { return &term{ tk: *tk, - class: classOperator, - kind: kindInteger, children: make([]*term, 0, 1), position: posPostfix, priority: priFact, diff --git a/operator-prod.go b/operator-prod.go index 0c7d506..f19023d 100644 --- a/operator-prod.go +++ b/operator-prod.go @@ -13,9 +13,9 @@ import ( func newMultiplyTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindUnknown, + tk: *tk, + // class: classOperator, + // kind: kindUnknown, children: make([]*term, 0, 2), position: posInfix, priority: priProduct, @@ -52,9 +52,9 @@ func evalMultiply(ctx ExprContext, self *term) (v any, err error) { func newDivideTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindUnknown, + tk: *tk, + // class: classOperator, + // kind: kindUnknown, children: make([]*term, 0, 2), position: posInfix, priority: priProduct, @@ -96,8 +96,6 @@ func evalDivide(ctx ExprContext, self *term) (v any, err error) { func newDivideAsFloatTerm(tk *Token) (inst *term) { return &term{ tk: *tk, - class: classOperator, - kind: kindUnknown, children: make([]*term, 0, 2), position: posInfix, priority: priProduct, @@ -129,9 +127,9 @@ func evalDivideAsFloat(ctx ExprContext, self *term) (v any, err error) { func newReminderTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindUnknown, + tk: *tk, + // class: classOperator, + // kind: kindUnknown, children: make([]*term, 0, 2), position: posInfix, priority: priProduct, diff --git a/operator-rel.go b/operator-rel.go index fe9c40b..761df89 100644 --- a/operator-rel.go +++ b/operator-rel.go @@ -8,9 +8,9 @@ package expr func newEqualTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindBool, + tk: *tk, + // class: classOperator, + // kind: kindBool, children: make([]*term, 0, 2), position: posInfix, priority: priRelational, @@ -47,9 +47,9 @@ func evalEqual(ctx ExprContext, self *term) (v any, err error) { func newNotEqualTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindBool, + tk: *tk, + // class: classOperator, + // kind: kindBool, children: make([]*term, 0, 2), position: posInfix, priority: priRelational, @@ -94,9 +94,9 @@ func evalNotEqual(ctx ExprContext, self *term) (v any, err error) { func newLessTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindBool, + tk: *tk, + // class: classOperator, + // kind: kindBool, children: make([]*term, 0, 2), position: posInfix, priority: priRelational, @@ -134,8 +134,6 @@ func evalLess(ctx ExprContext, self *term) (v any, err error) { func newLessEqualTerm(tk *Token) (inst *term) { return &term{ tk: *tk, - class: classOperator, - kind: kindUnknown, children: make([]*term, 0, 2), position: posInfix, priority: priRelational, @@ -172,9 +170,9 @@ func evalLessEqual(ctx ExprContext, self *term) (v any, err error) { func newGreaterTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindBool, + tk: *tk, + // class: classOperator, + // kind: kindBool, children: make([]*term, 0, 2), position: posInfix, priority: priRelational, @@ -194,9 +192,9 @@ func evalGreater(ctx ExprContext, self *term) (v any, err error) { func newGreaterEqualTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindBool, + tk: *tk, + // class: classOperator, + // kind: kindBool, children: make([]*term, 0, 2), position: posInfix, priority: priRelational, diff --git a/operator-selector.go b/operator-selector.go index 8034544..9cc864a 100644 --- a/operator-selector.go +++ b/operator-selector.go @@ -9,8 +9,6 @@ package expr func newSelectorTerm(tk *Token) (inst *term) { return &term{ tk: *tk, - class: classOperator, - kind: kindUnknown, children: make([]*term, 0, 3), position: posMultifix, priority: priSelector, diff --git a/operator-sign.go b/operator-sign.go index be3febc..d6a2ab1 100644 --- a/operator-sign.go +++ b/operator-sign.go @@ -8,9 +8,9 @@ package expr func newPlusSignTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindUnknown, + tk: *tk, + // class: classOperator, + // kind: kindUnknown, children: make([]*term, 0, 1), position: posPrefix, priority: priSign, @@ -21,8 +21,6 @@ func newPlusSignTerm(tk *Token) (inst *term) { func newMinusSignTerm(tk *Token) (inst *term) { return &term{ tk: *tk, - class: classOperator, - kind: kindUnknown, children: make([]*term, 0, 1), position: posPrefix, priority: priSign, diff --git a/operator-sum.go b/operator-sum.go index 21fd01a..ac0f21b 100644 --- a/operator-sum.go +++ b/operator-sum.go @@ -14,8 +14,6 @@ import ( func newPlusTerm(tk *Token) (inst *term) { return &term{ tk: *tk, - class: classOperator, - kind: kindUnknown, children: make([]*term, 0, 2), position: posInfix, priority: priSum, @@ -67,9 +65,9 @@ func evalPlus(ctx ExprContext, self *term) (v any, err error) { func newMinusTerm(tk *Token) (inst *term) { return &term{ - tk: *tk, - class: classOperator, - kind: kindUnknown, + tk: *tk, + // class: classOperator, + // kind: kindUnknown, children: make([]*term, 0, 2), position: posInfix, priority: priSum, diff --git a/term.go b/term.go index f39a752..abecca3 100644 --- a/term.go +++ b/term.go @@ -8,27 +8,6 @@ import ( "strings" ) -type termKind uint16 - -const ( - kindUnknown termKind = iota - kindBool - kindInteger - kindFloat - kindString - kindIdentifier -) - -type termClass uint16 - -const ( - classNull termClass = iota - classConst - classVar - classFunc - classOperator -) - type termPriority uint32 const ( @@ -60,23 +39,11 @@ const ( type evalFuncType func(ctx ExprContext, self *term) (v any, err error) -// type iterm interface { -// getClass() termClass -// getKind() termKind -// compute(ctx exprContext) (v any, err error) -// // isOperator() bool -// // isOperand() bool -// source() string -// setParent(parentNode term) -// } - type term struct { tk Token - class termClass - kind termKind parent *term children []*term - position termPosition // operator position: infix, prefix, suffix + position termPosition // operator position: leaf, infix, prefix, postfix, multifix priority termPriority // operator priority: higher value means higher priority evalFunc evalFuncType } @@ -169,7 +136,7 @@ func (self *term) value() any { func (self *term) compute(ctx ExprContext) (v any, err error) { if self.evalFunc == nil { - err = self.tk.Errorf("undefined eval-func for %v term type", self.kind) + err = self.tk.Errorf("undefined eval-func for %q term", self.source()) } else { v, err = self.evalFunc(ctx, self) }