Reduced token size

This commit is contained in:
Eduard Urbach 2024-07-21 14:35:06 +02:00
parent 7bfd0e731d
commit 1e3705df55
Signed by: eduard
GPG key ID: 49226B848C78F6C8
47 changed files with 543 additions and 764 deletions

View file

@ -15,39 +15,39 @@ type Operator struct {
// Operators defines the operators used in the language.
// The number corresponds to the operator priority and can not be zero.
var Operators = map[string]*Operator{
".": {".", 13, 2},
"λ": {"λ", 12, 1},
"@": {"@", 12, 2},
"!": {"!", 11, 1},
"*": {"*", 10, 2},
"/": {"/", 10, 2},
"%": {"%", 10, 2},
"+": {"+", 9, 2},
"-": {"-", 9, 2},
">>": {">>", 8, 2},
"<<": {"<<", 8, 2},
"&": {"&", 7, 2},
"^": {"^", 6, 2},
"|": {"|", 5, 2},
var Operators = map[token.Kind]*Operator{
token.Period: {".", 13, 2},
token.Call: {"λ", 12, 1},
token.Array: {"@", 12, 2},
token.Not: {"!", 11, 1},
token.Mul: {"*", 10, 2},
token.Div: {"/", 10, 2},
token.Mod: {"%", 10, 2},
token.Add: {"+", 9, 2},
token.Sub: {"-", 9, 2},
token.Shr: {">>", 8, 2},
token.Shl: {"<<", 8, 2},
token.And: {"&", 7, 2},
token.Xor: {"^", 6, 2},
token.Or: {"|", 5, 2},
">": {">", 4, 2},
"<": {"<", 4, 2},
">=": {">=", 4, 2},
"<=": {"<=", 4, 2},
"==": {"==", 3, 2},
"!=": {"!=", 3, 2},
"&&": {"&&", 2, 2},
"||": {"||", 1, 2},
token.Greater: {">", 4, 2},
token.Less: {"<", 4, 2},
token.GreaterEqual: {">=", 4, 2},
token.LessEqual: {"<=", 4, 2},
token.Equal: {"==", 3, 2},
token.NotEqual: {"!=", 3, 2},
token.LogicalAnd: {"&&", 2, 2},
token.LogicalOr: {"||", 1, 2},
"=": {"=", math.MinInt8, 2},
":=": {":=", math.MinInt8, 2},
"+=": {"+=", math.MinInt8, 2},
"-=": {"-=", math.MinInt8, 2},
"*=": {"*=", math.MinInt8, 2},
"/=": {"/=", math.MinInt8, 2},
">>=": {">>=", math.MinInt8, 2},
"<<=": {"<<=", math.MinInt8, 2},
token.Assign: {"=", math.MinInt8, 2},
token.Define: {":=", math.MinInt8, 2},
token.AddAssign: {"+=", math.MinInt8, 2},
token.SubAssign: {"-=", math.MinInt8, 2},
token.MulAssign: {"*=", math.MinInt8, 2},
token.DivAssign: {"/=", math.MinInt8, 2},
token.ShrAssign: {">>=", math.MinInt8, 2},
token.ShlAssign: {"<<=", math.MinInt8, 2},
}
func isComplete(expr *Expression) bool {
@ -59,14 +59,14 @@ func isComplete(expr *Expression) bool {
return true
}
if expr.Token.Kind == token.Operator && len(expr.Children) == numOperands(expr.Token.Text()) {
if expr.Token.IsOperator() && len(expr.Children) == numOperands(expr.Token.Kind) {
return true
}
return false
}
func numOperands(symbol string) int {
func numOperands(symbol token.Kind) int {
operator, exists := Operators[symbol]
if !exists {
@ -76,7 +76,7 @@ func numOperands(symbol string) int {
return operator.Operands
}
func precedence(symbol string) int8 {
func precedence(symbol token.Kind) int8 {
operator, exists := Operators[symbol]
if !exists {