Restore recursive reference to expr parser in atom parser

This commit is contained in:
2020-03-05 21:00:40 +01:00
parent a9758c5a94
commit cf0ceba925
2 changed files with 12 additions and 1 deletions

View File

@@ -2,5 +2,5 @@ import interpreter.Interpreter
fun main(args: Array<String>) {
val interpreter = Interpreter()
interpreter.run("2 + 2 * 2 / 2 ** 2")
interpreter.run("2 * (2 + 2)")
}

View File

@@ -2,11 +2,22 @@ package dsl.ast.parser
import dsl.ast.model.entity.ParserOutput
import dsl.token.model.entity.TokenList
import dsl.token.model.enumeration.TokenType
class AtomParser : Parser() {
override fun tryToParse(input: TokenList): ParserOutput {
val parenthesesParser = allOf(
listOf(
terminal(TokenType.OPEN_PAREN),
ExpressionParser(),
terminal(TokenType.CLOSE_PAREN)
)
) {
it[1]
}
val literalParser = oneOf(
listOf(
parenthesesParser,
BoolLiteralParser(),
FloatLiteralParser(),
IntegerLiteralParser(),