diff --git a/kotlin/forth/src/main/kotlin/ForthEvaluator.kt b/kotlin/forth/src/main/kotlin/ForthEvaluator.kt index 5cdfd8f..6979fd3 100644 --- a/kotlin/forth/src/main/kotlin/ForthEvaluator.kt +++ b/kotlin/forth/src/main/kotlin/ForthEvaluator.kt @@ -15,11 +15,19 @@ class ForthEvaluator { } } return emptyList() + } - // TODO: This needs to actually work? private fun validateToken(token: String): Boolean { - require(if (token.toInt() >= 0){ true } else token in validOps) - return false + if (token !in validOps) { + try { + token.toInt() + } catch (e: NumberFormatException) { + if (token !in validOps) { + throw IllegalArgumentException("No definition available for operator \"$token\"") + } + } + } + return true } }