aboutsummaryrefslogtreecommitdiff
path: root/example/math_expression
diff options
context:
space:
mode:
Diffstat (limited to 'example/math_expression')
-rw-r--r--example/math_expression/main.go12
-rw-r--r--example/math_expression/rpn.go11
-rw-r--r--example/math_expression/stack.go2
3 files changed, 15 insertions, 10 deletions
diff --git a/example/math_expression/main.go b/example/math_expression/main.go
index 35f7c3b..bfece39 100644
--- a/example/math_expression/main.go
+++ b/example/math_expression/main.go
@@ -1,3 +1,5 @@
+// +build example
+
package main
import (
@@ -6,16 +8,6 @@ import (
"github.com/neonxp/unilex"
)
-var output []unilex.Lexem = []unilex.Lexem{}
-var opPriority = map[string]int{
- "^": 3,
- "!": 3,
- "*": 2,
- "/": 2,
- "+": 1,
- "-": 1,
-}
-
func main() {
l := unilex.New("10 * (20.0 + 30.0)")
diff --git a/example/math_expression/rpn.go b/example/math_expression/rpn.go
index b65983d..84de59c 100644
--- a/example/math_expression/rpn.go
+++ b/example/math_expression/rpn.go
@@ -1,3 +1,5 @@
+// +build example
+
package main
// Helper functions to convert infix notation to RPN and calculates expression result.
@@ -10,6 +12,15 @@ import (
"github.com/neonxp/unilex"
)
+var opPriority = map[string]int{
+ "^": 3,
+ "!": 3,
+ "*": 2,
+ "/": 2,
+ "+": 1,
+ "-": 1,
+}
+
func infixToRPNotation(l *unilex.Lexer) []unilex.Lexem {
output := []unilex.Lexem{}
stack := lexemStack{}
diff --git a/example/math_expression/stack.go b/example/math_expression/stack.go
index 2ca8acc..b6c37b9 100644
--- a/example/math_expression/stack.go
+++ b/example/math_expression/stack.go
@@ -1,3 +1,5 @@
+// +build example
+
package main
// Simple lexem stack implementation.