Kotlin - Forth WIP2
This commit is contained in:
parent
3af3ff908f
commit
e126e0f498
2 changed files with 13 additions and 5 deletions
|
@ -1,16 +1,25 @@
|
|||
import java.util.*
|
||||
|
||||
class ForthEvaluator {
|
||||
val stack: Stack<Char> = Stack<Char>()
|
||||
val stack: Stack<String> = Stack<String>()
|
||||
val overridenOperators = mutableMapOf<Char, Char>()
|
||||
|
||||
private val validOps = listOf<String>("+", "-", "*", "/", "dup", "drop", "swap", "over")
|
||||
|
||||
fun evaluateProgram(inpList: List<String>): List<Int>{
|
||||
for (i in inpList){
|
||||
val tokenized = i.toList().filter { it != ' ' }
|
||||
for (i in tokenized){
|
||||
stack.push(i)
|
||||
val tokenized = i.split(' ')
|
||||
tokenized.all { validateToken(it) }
|
||||
for (j in tokenized){
|
||||
stack.push(j)
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -340,7 +340,6 @@ class ForthEvaluatorTest {
|
|||
forthEvaluator.evaluateProgram(listOf(": 1 2 ;"))
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun testErrorIfEvaluatingAnUndefinedOperator() {
|
||||
expectedException.expect(IllegalArgumentException::class.java)
|
||||
|
|
Loading…
Add table
Reference in a new issue