Implemented an abstract syntax tree
This commit is contained in:
parent
3b29d4cdee
commit
8453273d73
28 changed files with 422 additions and 315 deletions
|
@ -9,7 +9,7 @@ import (
|
|||
// Operator represents an operator for mathematical expressions.
|
||||
type Operator struct {
|
||||
Symbol string
|
||||
Precedence int
|
||||
Precedence int8
|
||||
Operands int
|
||||
}
|
||||
|
||||
|
@ -39,14 +39,14 @@ var Operators = map[string]*Operator{
|
|||
"&&": {"&&", 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},
|
||||
"=": {"=", math.MinInt8, 2},
|
||||
":=": {":=", math.MinInt8, 2},
|
||||
"+=": {"+=", math.MinInt8, 2},
|
||||
"-=": {"-=", math.MinInt8, 2},
|
||||
"*=": {"*=", math.MinInt8, 2},
|
||||
"/=": {"/=", math.MinInt8, 2},
|
||||
">>=": {">>=", math.MinInt8, 2},
|
||||
"<<=": {"<<=", math.MinInt8, 2},
|
||||
}
|
||||
|
||||
func isComplete(expr *Expression) bool {
|
||||
|
@ -75,7 +75,7 @@ func numOperands(symbol string) int {
|
|||
return operator.Operands
|
||||
}
|
||||
|
||||
func precedence(symbol string) int {
|
||||
func precedence(symbol string) int8 {
|
||||
operator, exists := Operators[symbol]
|
||||
|
||||
if !exists {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue