Checkpoint
This commit is contained in:
parent
43b364044e
commit
9db1c66781
34 changed files with 746 additions and 194 deletions
|
@ -1,16 +1,10 @@
|
|||
package parser.grammars
|
||||
|
||||
import com.github.h0tk3y.betterParse.combinators.or
|
||||
import com.github.h0tk3y.betterParse.combinators.separated
|
||||
import com.github.h0tk3y.betterParse.combinators.times
|
||||
import com.github.h0tk3y.betterParse.combinators.unaryMinus
|
||||
import com.github.h0tk3y.betterParse.combinators.use
|
||||
import com.github.h0tk3y.betterParse.combinators.*
|
||||
import com.github.h0tk3y.betterParse.grammar.parser
|
||||
import com.github.h0tk3y.betterParse.parser.Parser
|
||||
import prolog.ast.arithmetic.Expression
|
||||
import prolog.ast.arithmetic.Float
|
||||
import prolog.ast.arithmetic.Integer
|
||||
import prolog.ast.logic.LogicOperand
|
||||
import prolog.ast.terms.*
|
||||
|
||||
open class TermsGrammar : Tokens() {
|
||||
|
@ -37,42 +31,32 @@ open class TermsGrammar : Tokens() {
|
|||
protected val float: Parser<Float> by floatToken use { Float(text.toFloat()) }
|
||||
|
||||
// Operators
|
||||
protected val logOps: Parser<String> by (dummy
|
||||
protected val ops: Parser<String> by (dummy
|
||||
// Logic
|
||||
or comma
|
||||
or semicolon
|
||||
// Arithmetic
|
||||
or plus
|
||||
or equals
|
||||
or notEquals
|
||||
) use { this.text }
|
||||
protected val simpleLogicOperand: Parser<LogicOperand> by (dummy
|
||||
protected val simpleOperand: Parser<Operand> by (dummy
|
||||
// Logic
|
||||
or compound
|
||||
or atom
|
||||
)
|
||||
protected val logicOperand: Parser<LogicOperand> by (dummy
|
||||
or parser(::logicOperator)
|
||||
or simpleLogicOperand
|
||||
)
|
||||
protected val logicOperator: Parser<CompoundTerm> by (simpleLogicOperand * logOps * logicOperand) use {
|
||||
CompoundTerm(Atom(t2), listOf(t1, t3))
|
||||
}
|
||||
|
||||
protected val arithmeticOps: Parser<String> by (dummy
|
||||
or plus
|
||||
) use { this.text }
|
||||
protected val simpleArithmeticOperand: Parser<Expression> by (dummy
|
||||
or variable
|
||||
// Arithmetic
|
||||
or int
|
||||
or float
|
||||
)
|
||||
protected val arithmeticOperand: Parser<Expression> by (dummy
|
||||
or parser(::arithmeticOperator)
|
||||
or simpleArithmeticOperand
|
||||
) use { this as Expression }
|
||||
protected val arithmeticOperator: Parser<CompoundTerm> by (simpleArithmeticOperand * arithmeticOps * arithmeticOperand) use {
|
||||
protected val operand: Parser<Operand> by (dummy
|
||||
or parser(::operator)
|
||||
or simpleOperand
|
||||
)
|
||||
protected val operator: Parser<CompoundTerm> by (simpleOperand * ops * operand) use {
|
||||
CompoundTerm(Atom(t2), listOf(t1, t3))
|
||||
}
|
||||
|
||||
protected val operator: Parser<CompoundTerm> by (dummy
|
||||
or logicOperator
|
||||
or arithmeticOperator
|
||||
)
|
||||
|
||||
// Parts
|
||||
protected val head: Parser<Head> by (dummy
|
||||
or compound
|
||||
|
@ -81,6 +65,7 @@ open class TermsGrammar : Tokens() {
|
|||
protected val body: Parser<Body> by (dummy
|
||||
or operator
|
||||
or head
|
||||
or variable
|
||||
) use { this as Body }
|
||||
|
||||
protected val term: Parser<Term> by (dummy
|
||||
|
|
Reference in a new issue