mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 05:10:55 +00:00
Cleanup TokenType
This commit is contained in:
parent
ef4045ecb4
commit
f1645d0924
@ -2,7 +2,7 @@ package gay.pizza.pork.eval
|
|||||||
|
|
||||||
import gay.pizza.pork.ast.*
|
import gay.pizza.pork.ast.*
|
||||||
|
|
||||||
class Evaluator(root: Scope) : Visitor<Any> {
|
class PorkEvaluator(root: Scope) : Visitor<Any> {
|
||||||
private var currentScope: Scope = root
|
private var currentScope: Scope = root
|
||||||
|
|
||||||
override fun visitDefine(node: Define): Any {
|
override fun visitDefine(node: Define): Any {
|
@ -2,7 +2,7 @@ package gay.pizza.pork
|
|||||||
|
|
||||||
import gay.pizza.pork.ast.*
|
import gay.pizza.pork.ast.*
|
||||||
import gay.pizza.pork.eval.Scope
|
import gay.pizza.pork.eval.Scope
|
||||||
import gay.pizza.pork.eval.Evaluator
|
import gay.pizza.pork.eval.PorkEvaluator
|
||||||
import gay.pizza.pork.parse.*
|
import gay.pizza.pork.parse.*
|
||||||
import kotlin.io.path.Path
|
import kotlin.io.path.Path
|
||||||
import kotlin.io.path.readText
|
import kotlin.io.path.readText
|
||||||
@ -10,7 +10,7 @@ import kotlin.io.path.readText
|
|||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
fun eval(ast: Program) {
|
fun eval(ast: Program) {
|
||||||
val scope = Scope()
|
val scope = Scope()
|
||||||
val evaluator = Evaluator(scope)
|
val evaluator = PorkEvaluator(scope)
|
||||||
evaluator.visit(ast)
|
evaluator.visit(ast)
|
||||||
println("> ${scope.call("main")}")
|
println("> ${scope.call("main")}")
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ class PorkTokenizer(val source: CharSource) {
|
|||||||
tokenStart = source.currentIndex
|
tokenStart = source.currentIndex
|
||||||
val char = source.next()
|
val char = source.next()
|
||||||
for (item in TokenType.SingleChars) {
|
for (item in TokenType.SingleChars) {
|
||||||
if (item.singleChar == char) {
|
if (item.char == char) {
|
||||||
return Token(item, char.toString())
|
return Token(item, char.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,27 @@
|
|||||||
package gay.pizza.pork.parse
|
package gay.pizza.pork.parse
|
||||||
|
|
||||||
enum class TokenType(val singleChar: Char? = null, val keyword: String? = null) {
|
enum class TokenType(val char: Char? = null, val keyword: String? = null) {
|
||||||
Symbol,
|
Symbol,
|
||||||
IntLiteral,
|
IntLiteral,
|
||||||
Equals(singleChar = '='),
|
Equals(char = '='),
|
||||||
Plus(singleChar = '+'),
|
Plus(char = '+'),
|
||||||
Minus(singleChar = '-'),
|
Minus(char = '-'),
|
||||||
Multiply(singleChar = '*'),
|
Multiply(char = '*'),
|
||||||
Divide(singleChar = '/'),
|
Divide(char = '/'),
|
||||||
LeftCurly(singleChar = '{'),
|
LeftCurly(char = '{'),
|
||||||
RightCurly(singleChar = '}'),
|
RightCurly(char = '}'),
|
||||||
LeftBracket(singleChar = '['),
|
LeftBracket(char = '['),
|
||||||
RightBracket(singleChar = ']'),
|
RightBracket(char = ']'),
|
||||||
LeftParentheses(singleChar = '('),
|
LeftParentheses(char = '('),
|
||||||
RightParentheses(singleChar = ')'),
|
RightParentheses(char = ')'),
|
||||||
Comma(singleChar = ','),
|
Comma(char = ','),
|
||||||
False(keyword = "false"),
|
False(keyword = "false"),
|
||||||
True(keyword = "true"),
|
True(keyword = "true"),
|
||||||
|
In(keyword = "in"),
|
||||||
EndOfFile;
|
EndOfFile;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val Keywords = entries.filter { it.keyword != null }
|
val Keywords = entries.filter { it.keyword != null }
|
||||||
val SingleChars = entries.filter { it.singleChar != null }
|
val SingleChars = entries.filter { it.char != null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user