Fix examples
This commit is contained in:
parent
8399e3834b
commit
df3a032c52
3 changed files with 15 additions and 10 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
// +build example
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -6,16 +8,6 @@ import (
|
||||||
"github.com/neonxp/unilex"
|
"github.com/neonxp/unilex"
|
||||||
)
|
)
|
||||||
|
|
||||||
var output []unilex.Lexem = []unilex.Lexem{}
|
|
||||||
var opPriority = map[string]int{
|
|
||||||
"^": 3,
|
|
||||||
"!": 3,
|
|
||||||
"*": 2,
|
|
||||||
"/": 2,
|
|
||||||
"+": 1,
|
|
||||||
"-": 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
l := unilex.New("10 * (20.0 + 30.0)")
|
l := unilex.New("10 * (20.0 + 30.0)")
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// +build example
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
// Helper functions to convert infix notation to RPN and calculates expression result.
|
// Helper functions to convert infix notation to RPN and calculates expression result.
|
||||||
|
@ -10,6 +12,15 @@ import (
|
||||||
"github.com/neonxp/unilex"
|
"github.com/neonxp/unilex"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var opPriority = map[string]int{
|
||||||
|
"^": 3,
|
||||||
|
"!": 3,
|
||||||
|
"*": 2,
|
||||||
|
"/": 2,
|
||||||
|
"+": 1,
|
||||||
|
"-": 1,
|
||||||
|
}
|
||||||
|
|
||||||
func infixToRPNotation(l *unilex.Lexer) []unilex.Lexem {
|
func infixToRPNotation(l *unilex.Lexer) []unilex.Lexem {
|
||||||
output := []unilex.Lexem{}
|
output := []unilex.Lexem{}
|
||||||
stack := lexemStack{}
|
stack := lexemStack{}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// +build example
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
// Simple lexem stack implementation.
|
// Simple lexem stack implementation.
|
||||||
|
|
Loading…
Reference in a new issue