retrofitted arithmetic functions

This commit is contained in:
Aidan 2020-06-29 12:51:41 -07:00
parent f3e39e156c
commit 7c630d5a38
No known key found for this signature in database
GPG key ID: 327711E983899316
4 changed files with 264 additions and 1 deletions

View file

@ -24,6 +24,8 @@ import (
)
func not(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
in = in.Eval(ft, vt)
if in.Tag != ast.BOOL {
log.Log(log.ERR, "non-bool argument to 'not'", "not")
return nil
@ -96,10 +98,24 @@ func eq(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
out = "F"
}
case ast.NUMBER, ast.STRING, ast.BOOL:
case ast.STRING, ast.BOOL:
if in.Value() != second.Value() {
out = "F"
}
case ast.NUMBER:
l_val, parse_err := strconv.ParseFloat(in.Value(), 64)
r_val, parse_err := strconv.ParseFloat(second.Value(), 64)
if parse_err != nil {
log.Log(log.ERR,
"error parsing number: "+parse_err.Error(),
"eq")
return nil
}
if l_val != r_val {
out = "F"
}
}
}