Enforced consistent naming

This commit is contained in:
2024-06-26 23:24:11 +02:00
parent d1a3ffb1a5
commit 94151773a5
10 changed files with 180 additions and 150 deletions

@ -1,6 +1,10 @@
package expression
import "git.akyoto.dev/cli/q/src/build/token"
import (
"math"
"git.akyoto.dev/cli/q/src/build/token"
)
// Operator represents an operator for mathematical expressions.
type Operator struct {
@ -12,35 +16,35 @@ 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{
".": {".", 14, 2},
"λ": {"λ", 13, 1},
"!": {"!", 12, 1},
"*": {"*", 11, 2},
"/": {"/", 11, 2},
"%": {"%", 11, 2},
"+": {"+", 10, 2},
"-": {"-", 10, 2},
">>": {">>", 9, 2},
"<<": {"<<", 9, 2},
">": {">", 8, 2},
"<": {"<", 8, 2},
">=": {">=", 8, 2},
"<=": {"<=", 8, 2},
"==": {"==", 7, 2},
"!=": {"!=", 7, 2},
"&": {"&", 6, 2},
"^": {"^", 5, 2},
"|": {"|", 4, 2},
"&&": {"&&", 3, 2},
"||": {"||", 2, 2},
"=": {"=", 1, 2},
":=": {":=", 1, 2},
"+=": {"+=", 1, 2},
"-=": {"-=", 1, 2},
"*=": {"*=", 1, 2},
"/=": {"/=", 1, 2},
">>=": {">>=", 1, 2},
"<<=": {"<<=", 1, 2},
".": {".", 13, 2},
"λ": {"λ", 12, 1},
"!": {"!", 11, 1},
"*": {"*", 10, 2},
"/": {"/", 10, 2},
"%": {"%", 10, 2},
"+": {"+", 9, 2},
"-": {"-", 9, 2},
">>": {">>", 8, 2},
"<<": {"<<", 8, 2},
">": {">", 7, 2},
"<": {"<", 7, 2},
">=": {">=", 7, 2},
"<=": {"<=", 7, 2},
"==": {"==", 6, 2},
"!=": {"!=", 6, 2},
"&": {"&", 5, 2},
"^": {"^", 4, 2},
"|": {"|", 3, 2},
"&&": {"&&", 2, 2},
"||": {"||", 1, 2},
"=": {"=", math.MinInt, 2},
":=": {":=", math.MinInt, 2},
"+=": {"+=", math.MinInt, 2},
"-=": {"-=", math.MinInt, 2},
"*=": {"*=", math.MinInt, 2},
"/=": {"/=", math.MinInt, 2},
">>=": {">>=", math.MinInt, 2},
"<<=": {"<<=", math.MinInt, 2},
}
func isComplete(expr *Expression) bool {
@ -60,9 +64,21 @@ func isComplete(expr *Expression) bool {
}
func numOperands(symbol string) int {
return Operators[symbol].Operands
operator, exists := Operators[symbol]
if !exists {
return -1
}
return operator.Operands
}
func precedence(symbol string) int {
return Operators[symbol].Precedence
operator, exists := Operators[symbol]
if !exists {
return -1
}
return operator.Precedence
}