aboutsummaryrefslogtreecommitdiff
path: root/lexer.go
diff options
context:
space:
mode:
Diffstat (limited to 'lexer.go')
-rw-r--r--lexer.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/lexer.go b/lexer.go
index 8082e35..ec56ccc 100644
--- a/lexer.go
+++ b/lexer.go
@@ -2,6 +2,8 @@ package main
import (
"log"
+ "strconv"
+ "strings"
"unicode/utf8"
)
@@ -24,6 +26,24 @@ func (y *yyLex) Error(s string) {
func (y *yyLex) Lex(lval *yySymType) (ret int) {
item := <-y.items
+ switch item.typ {
+ case STRING:
+ lval.sval = item.val
+ case QUOTED:
+ lval.sval = strings.Replace(item.val, "''", "'", -1)
+ case INTEGER:
+ item.val = strings.Replace(item.val, "¯", "-", -1)
+ lval.ival, _ = strconv.Atoi(item.val)
+ case FLOAT:
+ item.val = strings.Replace(item.val, "¯", "-", -1)
+ lval.fval, _ = strconv.ParseFloat(item.val, 64)
+ case COMPLEX:
+ item.val = strings.Replace(item.val, "¯", "-", -1)
+ pos := strings.IndexAny(item.val, "jJ")
+ r, _ := strconv.ParseFloat(item.val[:pos], 64)
+ i, _ := strconv.ParseFloat(item.val[pos+1:], 64)
+ lval.cval = complex(r, i)
+ }
lval.sval = item.val
return item.typ
}