Last active
December 23, 2016 23:37
-
-
Save hcorion/104e46ddee6d3137d2f65e74f1690c6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import strutils | |
let vars = ["ACC", "BAK", "NIL"] | |
proc isNumber*(input: string): bool = | |
for i in 0..input.len-1: | |
if not input[i].isDigit: | |
return false | |
return true | |
proc checkVar[T](input: string): T = | |
if not input.isNumber: | |
var valid = false | |
for d in 0..vars.len-1: | |
if input == vars[d]: | |
valid = true | |
if valid: | |
return input | |
else: | |
return "" | |
else: | |
return input.parseInt | |
var newVar = checkVar("TES") | |
if newVar is string: | |
if newVar == "": | |
errors.add ASMError(text: "Instruction " & instruction.label & " was given an unkown variable " & io[0], line: i+1) | |
break finishedLine | |
elif newVar is int: | |
echo "The instruction, " & instruction.label & " has a correct numeric input: ", newVar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment