aboutsummaryrefslogtreecommitdiff
path: root/lexer.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-01-08 18:18:33 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-01-08 18:18:33 +0100
commit40aa6de8a706ac88a7451dad0058c59f26bd9a7f (patch)
tree6bfd1bd81e96757dea3f0947ab1e1926adde0422 /lexer.go
parent14ad206ae26716c619661c221b8c56c6627fbb3e (diff)
Replace runes with named tokens
Diffstat (limited to 'lexer.go')
-rw-r--r--lexer.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/lexer.go b/lexer.go
index 9049cbd..b059625 100644
--- a/lexer.go
+++ b/lexer.go
@@ -15,8 +15,23 @@ const (
upper
quoted
char
+ sum
+ sub
+ mul
+ div
)
+var charmap = map[rune]int {
+ '+': SUM,
+ '-': SUB,
+ '*': MUL,
+ '/': DIV,
+ '=': EQ,
+ '(': LBR,
+ ')': RBR,
+ ',': COM,
+}
+
type item struct {
typ int
val string
@@ -54,7 +69,12 @@ func (y *yyLex) Lex(lval *yySymType) int {
lval.sval = item.val[1:len(item.val)-1]
return STRING
case char:
- return int(item.val[0])
+ c := rune(item.val[0])
+ if ch, ok := charmap[c]; ok {
+ return ch
+ } else {
+ return int(c)
+ }
}
return eof
}