shunting_yard.go | |
---|---|
|
|
toRPN function transforms sequence of tokens with expression into PRN code gocyclo:ignore |
|
operators with precedence |
|
arithmetic operators |
|
relational operators |
|
logic operators |
|
tokenization implementation and token processing |
|
integer value can be added directly into output |
|
identifier can be added directly into output |
|
left paren is pushed into stack |
|
right paren start processing operands on stack (until first left paren is found) |
|
read value from stack (POP) |
|
remove left paren if found + stop operand processing |
|
other tokens poped from stack can be added to output |
|
special token marking end of tokenization |
|
traverse through values on stack |
|
TOP operation |
|
read priority for operator read from stack |
|
compare operator priorities |
|
priority of read operator is greater than: -> end of processing |
|
priority of read operator is less than or equal: -> process read operator and POP it from stack |
|
newly read operator needs to be pushed onto stack |
|
clean out the stack at end of processing |
|