Migrate term parser to Kotlin
This commit is contained in:
@@ -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")
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package dsl.ast.model.node
|
||||
|
||||
class ProductOperatorNode(lhs: Node, operator: Node, rhs: Node) : BinaryOperatorAbstractNode(lhs, operator, rhs)
|
||||
18
src/main/kotlin/dsl/ast/parser/TermParser.kt
Normal file
18
src/main/kotlin/dsl/ast/parser/TermParser.kt
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user