operator

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package operator have a bundle of code describing operator of arithmetics expression

Index

Constants

This section is empty.

Variables

View Source
var Operators = map[token.Token]*Operator{
	token.ADD: {
		Lit:           "+",
		Tok:           token.ADD,
		Precedence:    2,
		Associativity: L,
		ArgsLen:       2,
		Operation: func(args []float64) float64 {
			return args[1] + args[0]
		},
	},
	token.SUB: {
		Lit:           "-",
		Tok:           token.SUB,
		Precedence:    2,
		Associativity: L,
		ArgsLen:       2,
		Operation: func(args []float64) float64 {
			return args[1] - args[0]
		},
	},
	token.MUL: {
		Lit:           "*",
		Tok:           token.MUL,
		Precedence:    3,
		Associativity: L,
		ArgsLen:       2,
		Operation: func(args []float64) float64 {
			return args[1] * args[0]
		},
	},
	token.QUO: {
		Lit:           "/",
		Tok:           token.QUO,
		Precedence:    3,
		Associativity: L,
		ArgsLen:       2,
		Operation: func(args []float64) float64 {
			return args[1] / args[0]
		},
	},
	token.REM: {
		Lit:           "%",
		Tok:           token.REM,
		Precedence:    3,
		Associativity: L,
		ArgsLen:       2,
		Operation: func(args []float64) float64 {
			return math.Mod(args[1], args[0])
		},
	},
	token.XOR: {
		Lit:           "^",
		Tok:           token.XOR,
		Precedence:    4,
		Associativity: R,
		ArgsLen:       2,
		Operation: func(args []float64) float64 {
			return math.Pow(args[1], args[0])
		},
	},
}

Operators is a map of all supported operator

Functions

This section is empty.

Types

type Associativity

type Associativity uint

Associativity is an artificial type to declare an Associativity constants

const (
	// L is an Associativity for the LEFT
	L Associativity = iota
	// R is an Associativity for the RIGHT
	R
)

type Operator

type Operator struct {
	Lit           string
	Tok           token.Token
	Precedence    uint
	Associativity Associativity
	ArgsLen       int
	Operation     func(args []float64) float64
}

Operator describe a mathematical operator

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL