Migrate factor 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 -\"fsfsef\".13.15 @c:14 3.14")
|
||||
interpreter.run("true ** 123 ** 4 -\"fsfsef\".13.15 @c:14 3.14")
|
||||
}
|
||||
3
src/main/kotlin/dsl/ast/model/node/NotOperatorNode.kt
Normal file
3
src/main/kotlin/dsl/ast/model/node/NotOperatorNode.kt
Normal file
@@ -0,0 +1,3 @@
|
||||
package dsl.ast.model.node
|
||||
|
||||
class NotOperatorNode(operator: Node, operand: Node) : UnaryOperatorAbstractNode(operator, operand)
|
||||
3
src/main/kotlin/dsl/ast/model/node/PowerOperatorNode.kt
Normal file
3
src/main/kotlin/dsl/ast/model/node/PowerOperatorNode.kt
Normal file
@@ -0,0 +1,3 @@
|
||||
package dsl.ast.model.node
|
||||
|
||||
class PowerOperatorNode(lhs: Node, operator: Node, rhs: Node) : BinaryOperatorAbstractNode(lhs, operator, rhs)
|
||||
31
src/main/kotlin/dsl/ast/parser/FactorParser.kt
Normal file
31
src/main/kotlin/dsl/ast/parser/FactorParser.kt
Normal file
@@ -0,0 +1,31 @@
|
||||
package dsl.ast.parser
|
||||
|
||||
import dsl.ast.model.entity.ParserOutput
|
||||
import dsl.ast.model.node.NotOperatorNode
|
||||
import dsl.ast.model.node.PowerOperatorNode
|
||||
import dsl.token.model.entity.TokenList
|
||||
import dsl.token.model.enumeration.TokenType
|
||||
|
||||
class FactorParser : Parser() {
|
||||
override fun tryToParse(input: TokenList): ParserOutput {
|
||||
val factorParser = leftAssociativeOperator(
|
||||
UnitParser(),
|
||||
listOf(TokenType.DOUBLE_ASTERISK),
|
||||
UnitParser()
|
||||
) { lhs, operator, rhs ->
|
||||
PowerOperatorNode(lhs, operator, rhs)
|
||||
}
|
||||
|
||||
val notOperatorParser = allOf(listOf(
|
||||
terminal(TokenType.NOT),
|
||||
factorParser
|
||||
)) {
|
||||
NotOperatorNode(it[0], it[1])
|
||||
}
|
||||
|
||||
return oneOf(listOf(
|
||||
notOperatorParser,
|
||||
factorParser
|
||||
)).parse(input)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user