Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func TokeniseExpression(string expr) {
- numcache = ""
- exprTokens = []
- for char in expr.Replace(" ", "") {
- if precedences.ContainsKey(char) {
- // is an operator
- if len(numcache) > 0 {
- // numcache has a number in it
- exprTokens += ('number', numcache)
- // add token type 'number'
- }
- exprTokens += ('operator', char)
- // char is an operator type, add token
- } else if char is a digit {
- //1, 2, 3, etc.
- numcache += char
- // add to numcache
- }
- }
- if len(numcache) > 0 then exprTokens += ('number', numcache)
- // this is for the number at the end of the expression, which
- // hasn't been 'popped' off it yet
- return exprTokens
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement