Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //For right now this doesn't check variable names
- //And will only work on real expressions once parsed
- //IE 'IF 5+1==6 Then Print Hi'
- //A step to extract the values from variable names
- //And replace the tokens with their real values
- //Will solve this, but only with math and variables. There's still commands to parse within expressions and functions
- //This is mostly for handling an expression of the type if expression
- function evaluate_expression(tokenslist$() )
- state=false //Assume false
- comparison = false
- //The comparison operator wasn't found yet
- tokenamount = getarrayelements(tokenslist$() )
- //Begin the iteration over the tokens to attempt to make sense of the input
- //We expect equals ==
- //We need to find the equals sign
- //Find first occurence of equals sign
- for t=1 to tokenamount
- if tokenslist$(t) ="="
- firstsign = t
- exitfor
- endif
- next t
- //We have found the first equal sign.
- //We now need to make sure we are dealing with a comparison
- if tokenslist$(firstsign+1)="=" then comparison=true
- if tokenslist$(firstsign+1)<>"="
- print "Expected == operator but found = instead in expression. "
- endif
- //Generate the left string
- for a=1 to firstsign-1
- leftside$ = leftside$ + tokenslist$(a)
- next a
- //Generate the right string
- for b=firstsign+1 to tokenamount
- rightside$ = rightside$ + tokenslist$(b)
- next b
- //Run them both through simple math
- result_a = simplemath(leftside$)
- result_b = simplemath(rightside$)
- //Evaluate the situation
- if result_a = result_b then state=true
- if result_a <> result_b then state=false
- //Return the states
- endfunction state, comparison
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement