Migrate term parser to Kotlin

This commit is contained in:
2020-03-05 20:48:32 +01:00
parent 0d3cd2f430
commit e58d745071
3 changed files with 22 additions and 1 deletions

View File

@@ -2,5 +2,5 @@ import interpreter.Interpreter
fun main(args: Array<String>) {
val interpreter = Interpreter()
interpreter.run("true ** 123 ** 4 -\"fsfsef\".13.15 @c:14 3.14")
interpreter.run("2 ** 2 * true ** 123 ** 4 -\"fsfsef\".13.15 @c:14 3.14")
}

View File

@@ -0,0 +1,3 @@
package dsl.ast.model.node
class ProductOperatorNode(lhs: Node, operator: Node, rhs: Node) : BinaryOperatorAbstractNode(lhs, operator, rhs)

View File

@@ -0,0 +1,18 @@
package dsl.ast.parser
import dsl.ast.model.entity.ParserOutput
import dsl.ast.model.node.ProductOperatorNode
import dsl.token.model.entity.TokenList
import dsl.token.model.enumeration.TokenType
class TermParser : Parser() {
override fun tryToParse(input: TokenList): ParserOutput {
return leftAssociativeOperator(
FactorParser(),
listOf(TokenType.ASTERISK, TokenType.SLASH),
FactorParser()
) {
lhs, operator, rhs -> ProductOperatorNode(lhs, operator, rhs)
}.parse(input)
}
}