aboutsummaryrefslogtreecommitdiff
path: root/example/math_expression/rpn.go
diff options
context:
space:
mode:
Diffstat (limited to 'example/math_expression/rpn.go')
-rw-r--r--example/math_expression/rpn.go11
1 files changed, 11 insertions, 0 deletions
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{}