aboutsummaryrefslogtreecommitdiff
path: root/example/math_expression/main.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-02-02 22:17:30 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-02-02 22:17:30 +0300
commit9489f783e560f12310bc4fec9b6073489bc050af (patch)
treecc1edd18384f206947e671346094021c88b86a4c /example/math_expression/main.go
parentd8d462d3f91e85323ebe478b01fc4bdaae17afe9 (diff)
Fix example
Diffstat (limited to 'example/math_expression/main.go')
-rw-r--r--example/math_expression/main.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/example/math_expression/main.go b/example/math_expression/main.go
index bfece39..805028e 100644
--- a/example/math_expression/main.go
+++ b/example/math_expression/main.go
@@ -1,5 +1,3 @@
-// +build example
-
package main
import (
@@ -8,6 +6,13 @@ import (
"github.com/neonxp/unilex"
)
+const (
+ LP unilex.LexType = iota
+ RP
+ NUMBER
+ OPERATOR
+)
+
func main() {
l := unilex.New("10 * (20.0 + 30.0)")
@@ -29,13 +34,13 @@ func lexExpression(l *unilex.Lexer) unilex.StateFunc {
switch {
case l.Accept("("):
- l.Emit("LP")
+ l.Emit(LP)
case l.Accept(")"):
- l.Emit("RP")
+ l.Emit(RP)
case unilex.ScanNumber(l):
- l.Emit("NUMBER")
+ l.Emit(NUMBER)
case l.Accept("+-*/^!"):
- l.Emit("OPERATOR")
+ l.Emit(OPERATOR)
case l.Peek() == unilex.EOF:
return nil
default: