All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.org.luaj.vm2.parser.LuaParser.kt Maven / Gradle / Ivy

/* Generated By:JavaCC: Do not edit this line. LuaParser.java */
package org.luaj.vm2.parser

import org.luaj.vm2.*
import org.luaj.vm2.ast.*
import org.luaj.vm2.internal.*
import org.luaj.vm2.io.*
import kotlin.jvm.*

class LuaParser : LuaParserConstants {

    /** Generated Token Manager.  */
    var token_source: LuaParserTokenManager
    lateinit var charStream: SimpleCharStream
    /** Current token.  */
    var token: Token? = null
    /** Next token.  */
    var jj_nt: Token? = null
    private var jj_ntk: Int = 0
    private var jj_scanpos: Token? = null
    private var jj_lastpos: Token? = null
    private var jj_la: Int = 0
    private var jj_gen: Int = 0
    private val jj_la1 = IntArray(34)
    private val jj_2_rtns = arrayOfNulls(7)
    private var jj_rescan = false
    private var jj_gc = 0
    private val jj_ls = LookaheadSuccess()


    /** Get the next Token.  */
    val nextToken: Token
        get() {
            if (token!!.next != null)
                token = token!!.next
            else {
                token!!.next = token_source.nextToken
                token = token!!.next
            }
            jj_ntk = -1
            jj_gen++
            return token!!
        }

    private val jj_expentries = ArrayList()
    private var jj_expentry: IntArray? = null
    private var jj_kind = -1
    private val jj_lasttokens = IntArray(100)
    private var jj_endpos: Int = 0

    private fun LineInfo(): Long {
        return charStream.beginLine.toLong() shl 32 or charStream.beginColumn.toLong()
    }

    private fun L(e: SyntaxElement, startinfo: Long) {
        e.beginLine = (startinfo shr 32).toInt()
        e.beginColumn = startinfo.toShort()
        e.endLine = token!!.endLine
        e.endColumn = token!!.endColumn.toShort()
    }

    private fun L(e: SyntaxElement, starttoken: Token) {
        e.beginLine = starttoken.beginLine
        e.beginColumn = starttoken.beginColumn.toShort()
        e.endLine = token!!.endLine
        e.endColumn = token!!.endColumn.toShort()
    }

    /** Root production.  */

    fun Chunk(): Chunk {
        val b: Block
        val c: Chunk
        val i = LineInfo()
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            69 -> {
                jj_consume_token(69)
                token_source.SwitchTo(LuaParserConstants.IN_COMMENT)
            }
            else -> {
                jj_la1[0] = jj_gen
            }
        }
        b = Block()
        jj_consume_token(0)
        c = Chunk(b)
        L(c, i)
        run { if (true) return c }
        throw Error("Missing return statement in function")
    }


    fun Block(): Block {
        val b = org.luaj.vm2.ast.Block()
        var s: Stat?
        val i = LineInfo()
        label_1@ while (true) {
            when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
                LuaParserConstants.BREAK, LuaParserConstants.DO, LuaParserConstants.FOR, LuaParserConstants.FUNCTION, LuaParserConstants.GOTO, LuaParserConstants.IF, LuaParserConstants.LOCAL, LuaParserConstants.REPEAT, LuaParserConstants.WHILE, LuaParserConstants.NAME, LuaParserConstants.DBCOLON, 70, 75 -> Unit
                else -> {
                    jj_la1[1] = jj_gen
                    break@label_1
                }
            }
            s = Stat()
            b.add(s)
        }
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            LuaParserConstants.RETURN -> {
                s = ReturnStat()
                b.add(s)
            }
            else -> {
                jj_la1[2] = jj_gen
            }
        }
        L(b, i)
        run { if (true) return b }
        throw Error("Missing return statement in function")
    }


    fun Stat(): Stat? {
        val b: Block
        val b2: Block
        val e: Exp
        val e2: Exp
        var e3: Exp? = null
        val s: Stat
        val fn: FuncName
        val fb: FuncBody
        val n: Token
        val nl: List
        var el: List? = null
        val i = LineInfo()
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            70 -> {
                jj_consume_token(70)
                run { if (true) return null }
            }
            LuaParserConstants.DBCOLON -> {
                s = Label()
                L(s, i)
                run { if (true) return s }
            }
            LuaParserConstants.BREAK -> {
                jj_consume_token(LuaParserConstants.BREAK)
                s = Stat.breakstat()
                L(s, i)
                run { if (true) return s }
            }
            LuaParserConstants.GOTO -> {
                jj_consume_token(LuaParserConstants.GOTO)
                n = jj_consume_token(LuaParserConstants.NAME)
                s = Stat.gotostat(n.image!!)
                L(s, i)
                run { if (true) return s }
            }
            LuaParserConstants.DO -> {
                jj_consume_token(LuaParserConstants.DO)
                b = Block()
                jj_consume_token(LuaParserConstants.END)
                s = Stat.block(b)
                L(s, i)
                run { if (true) return s }
            }
            LuaParserConstants.WHILE -> {
                jj_consume_token(LuaParserConstants.WHILE)
                e = Exp()
                jj_consume_token(LuaParserConstants.DO)
                b = Block()
                jj_consume_token(LuaParserConstants.END)
                s = Stat.whiledo(e, b)
                L(s, i)
                run { if (true) return s }
            }
            LuaParserConstants.REPEAT -> {
                jj_consume_token(LuaParserConstants.REPEAT)
                b = Block()
                jj_consume_token(LuaParserConstants.UNTIL)
                e = Exp()
                s = Stat.repeatuntil(b, e)
                L(s, i)
                run { if (true) return s }
            }
            LuaParserConstants.IF -> {
                s = IfThenElse()
                L(s, i)
                run { if (true) return s }
            }
            else -> {
                jj_la1[5] = jj_gen
                if (jj_2_1(3)) {
                    jj_consume_token(LuaParserConstants.FOR)
                    n = jj_consume_token(LuaParserConstants.NAME)
                    jj_consume_token(71)
                    e = Exp()
                    jj_consume_token(72)
                    e2 = Exp()
                    when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
                        72 -> {
                            jj_consume_token(72)
                            e3 = Exp()
                        }
                        else -> {
                            jj_la1[3] = jj_gen
                        }
                    }
                    jj_consume_token(LuaParserConstants.DO)
                    b = Block()
                    jj_consume_token(LuaParserConstants.END)
                    s = Stat.fornumeric(n.image!!, e, e2, e3, b)
                    L(s, i)
                    run { if (true) return s }
                } else {
                    when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
                        LuaParserConstants.FOR -> {
                            jj_consume_token(LuaParserConstants.FOR)
                            nl = NameList()
                            jj_consume_token(LuaParserConstants.IN)
                            el = ExpList()
                            jj_consume_token(LuaParserConstants.DO)
                            b = Block()
                            jj_consume_token(LuaParserConstants.END)
                            s = Stat.forgeneric(nl, el, b)
                            L(s, i)
                            run { if (true) return s }
                        }
                        LuaParserConstants.FUNCTION -> {
                            jj_consume_token(LuaParserConstants.FUNCTION)
                            fn = FuncName()
                            fb = FuncBody()
                            s = Stat.functiondef(fn, fb)
                            L(s, i)
                            run { if (true) return s }
                        }
                        else -> {
                            jj_la1[6] = jj_gen
                            if (jj_2_2(2)) {
                                jj_consume_token(LuaParserConstants.LOCAL)
                                jj_consume_token(LuaParserConstants.FUNCTION)
                                n = jj_consume_token(LuaParserConstants.NAME)
                                fb = FuncBody()
                                s = Stat.localfunctiondef(n.image!!, fb)
                                L(s, i)
                                run { if (true) return s }
                            } else {
                                when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
                                    LuaParserConstants.LOCAL -> {
                                        jj_consume_token(LuaParserConstants.LOCAL)
                                        nl = NameList()
                                        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
                                            71 -> {
                                                jj_consume_token(71)
                                                el = ExpList()
                                            }
                                            else -> {
                                                jj_la1[4] = jj_gen
                                            }
                                        }
                                        s = Stat.localassignment(nl, el)
                                        L(s, i)
                                        run { if (true) return s }
                                    }
                                    LuaParserConstants.NAME, 75 -> {
                                        s = ExprStat()
                                        L(s, i)
                                        run { if (true) return s }
                                    }
                                    else -> {
                                        jj_la1[7] = jj_gen
                                        jj_consume_token(-1)
                                        throw ParseException()
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        throw Error("Missing return statement in function")
    }


    fun IfThenElse(): Stat {
        val b: Block
        var b2: Block
        var b3: Block? = null
        val e: Exp
        var e2: Exp
        var el: MutableList? = null
        var bl: MutableList? = null
        jj_consume_token(LuaParserConstants.IF)
        e = Exp()
        jj_consume_token(LuaParserConstants.THEN)
        b = Block()
        label_2@ while (true) {
            when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
                LuaParserConstants.ELSEIF -> Unit
                else -> {
                    jj_la1[8] = jj_gen
                    break@label_2
                }
            }
            jj_consume_token(LuaParserConstants.ELSEIF)
            e2 = Exp()
            jj_consume_token(LuaParserConstants.THEN)
            b2 = Block()
            if (el == null) el = ArrayList()
            if (bl == null) bl = ArrayList()
            el.add(e2)
            bl.add(b2)
        }
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            LuaParserConstants.ELSE -> {
                jj_consume_token(LuaParserConstants.ELSE)
                b3 = Block()
            }
            else -> {
                jj_la1[9] = jj_gen
            }
        }
        jj_consume_token(LuaParserConstants.END)
        run { if (true) return Stat.ifthenelse(e, b, el, bl, b3) }
        throw Error("Missing return statement in function")
    }


    fun ReturnStat(): Stat {
        var el: List? = null
        val s: Stat
        val i = LineInfo()
        jj_consume_token(LuaParserConstants.RETURN)
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            LuaParserConstants.LONGSTRING0, LuaParserConstants.LONGSTRING1, LuaParserConstants.LONGSTRING2, LuaParserConstants.LONGSTRING3, LuaParserConstants.LONGSTRINGN, LuaParserConstants.FALSE, LuaParserConstants.FUNCTION, LuaParserConstants.NIL, LuaParserConstants.NOT, LuaParserConstants.TRUE, LuaParserConstants.NAME, LuaParserConstants.NUMBER, LuaParserConstants.STRING, LuaParserConstants.CHARSTRING, 69, 75, 79, 80, 83 -> el =
                ExpList()
            else -> {
                jj_la1[10] = jj_gen
            }
        }
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            70 -> jj_consume_token(70)
            else -> {
                jj_la1[11] = jj_gen
            }
        }
        s = Stat.returnstat(el)
        L(s, i)
        run { if (true) return s }
        throw Error("Missing return statement in function")
    }


    fun Label(): Stat {
        val n: Token
        jj_consume_token(LuaParserConstants.DBCOLON)
        n = jj_consume_token(LuaParserConstants.NAME)
        jj_consume_token(LuaParserConstants.DBCOLON)
        run { if (true) return Stat.labelstat(n.image!!) }
        throw Error("Missing return statement in function")
    }


    fun ExprStat(): Stat {
        val p: Exp.PrimaryExp
        var s: Stat? = null
        val i = LineInfo()
        p = PrimaryExp()
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            71, 72 -> s = Assign(assertvarexp(p))
            else -> {
                jj_la1[12] = jj_gen
            }
        }
        if (s == null) {
            s = Stat.functioncall(assertfunccall(p))
        }
        L(s, i)
        run { if (true) return s }
        throw Error("Missing return statement in function")
    }


    fun Assign(v0: Exp.VarExp): Stat {
        val vl = ArrayList()
        vl.add(v0)
        var ve: Exp.VarExp
        val el: List
        val s: Stat
        val i = LineInfo()
        label_3@ while (true) {
            when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
                72 -> Unit
                else -> {
                    jj_la1[13] = jj_gen
                    break@label_3
                }
            }
            jj_consume_token(72)
            ve = VarExp()
            vl.add(ve)
        }
        jj_consume_token(71)
        el = ExpList()
        s = Stat.assignment(vl, el)
        L(s, i)
        run { if (true) return s }
        throw Error("Missing return statement in function")
    }


    fun VarExp(): Exp.VarExp {
        val p: Exp.PrimaryExp
        p = PrimaryExp()
        run { if (true) return assertvarexp(p) }
        throw Error("Missing return statement in function")
    }


    fun FuncName(): FuncName {
        var n: Token
        val f: FuncName
        n = jj_consume_token(LuaParserConstants.NAME)
        f = FuncName(n.image!!)
        label_4@ while (true) {
            when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
                73 -> Unit
                else -> {
                    jj_la1[14] = jj_gen
                    break@label_4
                }
            }
            jj_consume_token(73)
            n = jj_consume_token(LuaParserConstants.NAME)
            f.adddot(n.image!!)
        }
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            74 -> {
                jj_consume_token(74)
                n = jj_consume_token(LuaParserConstants.NAME)
                f.method = n.image
            }
            else -> {
                jj_la1[15] = jj_gen
            }
        }
        L(f, n)
        run { if (true) return f }
        throw Error("Missing return statement in function")
    }


    fun PrefixExp(): Exp.PrimaryExp {
        val n: Token
        val e: Exp
        val p: Exp.PrimaryExp
        val i = LineInfo()
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            LuaParserConstants.NAME -> {
                n = jj_consume_token(LuaParserConstants.NAME)
                p = Exp.nameprefix(n.image!!)
                L(p, i)
                run { if (true) return p }
            }
            75 -> {
                jj_consume_token(75)
                e = Exp()
                jj_consume_token(76)
                p = Exp.parensprefix(e)
                L(p, i)
                run { if (true) return p }
            }
            else -> {
                jj_la1[16] = jj_gen
                jj_consume_token(-1)
                throw ParseException()
            }
        }
        throw Error("Missing return statement in function")
    }


    fun PrimaryExp(): Exp.PrimaryExp {
        var p: Exp.PrimaryExp
        val i = LineInfo()
        p = PrefixExp()
        label_5@ while (true) {
            if (jj_2_3(2)) {
            } else {
                break@label_5
            }
            p = PostfixOp(p)
        }
        L(p, i)
        run { if (true) return p }
        throw Error("Missing return statement in function")
    }


    fun PostfixOp(lhs: Exp.PrimaryExp): Exp.PrimaryExp {
        val n: Token
        val e: Exp
        val a: FuncArgs
        val p: Exp.PrimaryExp
        val i = LineInfo()
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            73 -> {
                jj_consume_token(73)
                n = jj_consume_token(LuaParserConstants.NAME)
                p = Exp.fieldop(lhs, n.image!!)
                L(p, i)
                run { if (true) return p }
            }
            77 -> {
                jj_consume_token(77)
                e = Exp()
                jj_consume_token(78)
                p = Exp.indexop(lhs, e)
                L(p, i)
                run { if (true) return p }
            }
            74 -> {
                jj_consume_token(74)
                n = jj_consume_token(LuaParserConstants.NAME)
                a = FuncArgs()
                p = Exp.methodop(lhs, n.image!!, a)
                L(p, i)
                run { if (true) return p }
            }
            LuaParserConstants.LONGSTRING0, LuaParserConstants.LONGSTRING1, LuaParserConstants.LONGSTRING2, LuaParserConstants.LONGSTRING3, LuaParserConstants.LONGSTRINGN, LuaParserConstants.STRING, LuaParserConstants.CHARSTRING, 75, 80 -> {
                a = FuncArgs()
                p = Exp.functionop(lhs, a)
                L(p, i)
                run { if (true) return p }
            }
            else -> {
                jj_la1[17] = jj_gen
                jj_consume_token(-1)
                throw ParseException()
            }
        }
        throw Error("Missing return statement in function")
    }


    fun FuncArgs(): FuncArgs {
        var el: MutableList? = null
        val tc: TableConstructor
        val s: LuaString
        val a: FuncArgs
        val i = LineInfo()
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            75 -> {
                jj_consume_token(75)
                when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
                    LuaParserConstants.LONGSTRING0, LuaParserConstants.LONGSTRING1, LuaParserConstants.LONGSTRING2, LuaParserConstants.LONGSTRING3, LuaParserConstants.LONGSTRINGN, LuaParserConstants.FALSE, LuaParserConstants.FUNCTION, LuaParserConstants.NIL, LuaParserConstants.NOT, LuaParserConstants.TRUE, LuaParserConstants.NAME, LuaParserConstants.NUMBER, LuaParserConstants.STRING, LuaParserConstants.CHARSTRING, 69, 75, 79, 80, 83 -> el =
                        ExpList()
                    else -> {
                        jj_la1[18] = jj_gen
                    }
                }
                jj_consume_token(76)
                a = FuncArgs.explist(el)
                L(a, i)
                run { if (true) return a }
            }
            80 -> {
                tc = TableConstructor()
                a = FuncArgs.tableconstructor(tc)
                L(a, i)
                run { if (true) return a }
            }
            LuaParserConstants.LONGSTRING0, LuaParserConstants.LONGSTRING1, LuaParserConstants.LONGSTRING2, LuaParserConstants.LONGSTRING3, LuaParserConstants.LONGSTRINGN, LuaParserConstants.STRING, LuaParserConstants.CHARSTRING -> {
                s = Str()
                a = FuncArgs.string(s)
                L(a, i)
                run { if (true) return a }
            }
            else -> {
                jj_la1[19] = jj_gen
                jj_consume_token(-1)
                throw ParseException()
            }
        }
        throw Error("Missing return statement in function")
    }


    fun NameList(): List {
        val l = ArrayList()
        var name: Token
        name = jj_consume_token(LuaParserConstants.NAME)
        l.add(Name(name.image!!))
        label_6@ while (true) {
            if (jj_2_4(2)) {
            } else {
                break@label_6
            }
            jj_consume_token(72)
            name = jj_consume_token(LuaParserConstants.NAME)
            l.add(Name(name.image!!))
        }
        run { if (true) return l }
        throw Error("Missing return statement in function")
    }


    fun ExpList(): MutableList {
        val l = ArrayList()
        var e: Exp
        e = Exp()
        l.add(e)
        label_7@ while (true) {
            when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
                72 -> Unit
                else -> {
                    jj_la1[20] = jj_gen
                    break@label_7
                }
            }
            jj_consume_token(72)
            e = Exp()
            l.add(e)
        }
        run { if (true) return l }
        throw Error("Missing return statement in function")
    }


    fun SimpleExp(): Exp {
        val n: Token
        val s: LuaString
        val e: Exp
        val c: TableConstructor
        val b: FuncBody
        val i = LineInfo()
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            LuaParserConstants.NIL -> {
                jj_consume_token(LuaParserConstants.NIL)
                e = Exp.constant(LuaValue.NIL)
                L(e, i)
                run { if (true) return e }
            }
            LuaParserConstants.TRUE -> {
                jj_consume_token(LuaParserConstants.TRUE)
                e = Exp.constant(LuaValue.TRUE)
                L(e, i)
                run { if (true) return e }
            }
            LuaParserConstants.FALSE -> {
                jj_consume_token(LuaParserConstants.FALSE)
                e = Exp.constant(LuaValue.FALSE)
                L(e, i)
                run { if (true) return e }
            }
            LuaParserConstants.NUMBER -> {
                n = jj_consume_token(LuaParserConstants.NUMBER)
                e = Exp.numberconstant(n.image!!)
                L(e, i)
                run { if (true) return e }
            }
            LuaParserConstants.LONGSTRING0, LuaParserConstants.LONGSTRING1, LuaParserConstants.LONGSTRING2, LuaParserConstants.LONGSTRING3, LuaParserConstants.LONGSTRINGN, LuaParserConstants.STRING, LuaParserConstants.CHARSTRING -> {
                s = Str()
                e = Exp.constant(s)
                L(e, i)
                run { if (true) return e }
            }
            79 -> {
                jj_consume_token(79)
                e = Exp.varargs()
                L(e, i)
                run { if (true) return e }
            }
            80 -> {
                c = TableConstructor()
                e = Exp.tableconstructor(c)
                L(e, i)
                run { if (true) return e }
            }
            LuaParserConstants.FUNCTION -> {
                b = FunctionCall()
                e = Exp.anonymousfunction(b)
                L(e, i)
                run { if (true) return e }
            }
            LuaParserConstants.NAME, 75 -> {
                e = PrimaryExp()
                run { if (true) return e }
            }
            else -> {
                jj_la1[21] = jj_gen
                jj_consume_token(-1)
                throw ParseException()
            }
        }
        throw Error("Missing return statement in function")
    }


    fun Str(): LuaString {
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            LuaParserConstants.STRING -> {
                jj_consume_token(LuaParserConstants.STRING)
                run { if (true) return Str.quoteString(token!!.image!!) }
            }
            LuaParserConstants.CHARSTRING -> {
                jj_consume_token(LuaParserConstants.CHARSTRING)
                run { if (true) return Str.charString(token!!.image!!) }
            }
            LuaParserConstants.LONGSTRING0 -> {
                jj_consume_token(LuaParserConstants.LONGSTRING0)
                run { if (true) return Str.longString(token!!.image!!) }
            }
            LuaParserConstants.LONGSTRING1 -> {
                jj_consume_token(LuaParserConstants.LONGSTRING1)
                run { if (true) return Str.longString(token!!.image!!) }
            }
            LuaParserConstants.LONGSTRING2 -> {
                jj_consume_token(LuaParserConstants.LONGSTRING2)
                run { if (true) return Str.longString(token!!.image!!) }
            }
            LuaParserConstants.LONGSTRING3 -> {
                jj_consume_token(LuaParserConstants.LONGSTRING3)
                run { if (true) return Str.longString(token!!.image!!) }
            }
            LuaParserConstants.LONGSTRINGN -> {
                jj_consume_token(LuaParserConstants.LONGSTRINGN)
                run { if (true) return Str.longString(token!!.image!!) }
            }
            else -> {
                jj_la1[22] = jj_gen
                jj_consume_token(-1)
                throw ParseException()
            }
        }
        throw Error("Missing return statement in function")
    }


    fun Exp(): Exp {
        var e: Exp
        var s: Exp
        var op: Int
        val i = LineInfo()
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            LuaParserConstants.LONGSTRING0, LuaParserConstants.LONGSTRING1, LuaParserConstants.LONGSTRING2, LuaParserConstants.LONGSTRING3, LuaParserConstants.LONGSTRINGN, LuaParserConstants.FALSE, LuaParserConstants.FUNCTION, LuaParserConstants.NIL, LuaParserConstants.TRUE, LuaParserConstants.NAME, LuaParserConstants.NUMBER, LuaParserConstants.STRING, LuaParserConstants.CHARSTRING, 75, 79, 80 -> e =
                SimpleExp()
            LuaParserConstants.NOT, 69, 83 -> {
                op = Unop()
                s = Exp()
                e = Exp.unaryexp(op, s)
            }
            else -> {
                jj_la1[23] = jj_gen
                jj_consume_token(-1)
                throw ParseException()
            }
        }
        label_8@ while (true) {
            if (jj_2_5(2)) {
            } else {
                break@label_8
            }
            op = Binop()
            s = Exp()
            e = Exp.binaryexp(e, op, s)
        }
        L(e, i)
        run { if (true) return e }
        throw Error("Missing return statement in function")
    }


    fun FunctionCall(): FuncBody {
        val b: FuncBody
        val i = LineInfo()
        jj_consume_token(LuaParserConstants.FUNCTION)
        b = FuncBody()
        L(b, i)
        run { if (true) return b }
        throw Error("Missing return statement in function")
    }


    fun FuncBody(): FuncBody {
        var pl: ParList? = null
        val b: Block
        val f: FuncBody
        val i = LineInfo()
        jj_consume_token(75)
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            LuaParserConstants.NAME, 79 -> pl = ParList()
            else -> {
                jj_la1[24] = jj_gen
            }
        }
        jj_consume_token(76)
        b = Block()
        jj_consume_token(LuaParserConstants.END)
        f = FuncBody(pl, b)
        L(f, i)
        run { if (true) return f }
        throw Error("Missing return statement in function")
    }


    fun ParList(): ParList {
        var l: List? = null
        var v = false
        val p: ParList
        val i = LineInfo()
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            LuaParserConstants.NAME -> {
                l = NameList()
                when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
                    72 -> {
                        jj_consume_token(72)
                        jj_consume_token(79)
                        v = true
                    }
                    else -> {
                        jj_la1[25] = jj_gen
                    }
                }
                p = ParList(l, v)
                L(p, i)
                run { if (true) return p }
            }
            79 -> {
                jj_consume_token(79)
                p = ParList(null, true)
                L(p, i)
                run { if (true) return p }
            }
            else -> {
                jj_la1[26] = jj_gen
                jj_consume_token(-1)
                throw ParseException()
            }
        }
        throw Error("Missing return statement in function")
    }


    fun TableConstructor(): TableConstructor {
        val c = org.luaj.vm2.ast.TableConstructor()
        var l: List? = null
        val i = LineInfo()
        jj_consume_token(80)
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            LuaParserConstants.LONGSTRING0, LuaParserConstants.LONGSTRING1, LuaParserConstants.LONGSTRING2, LuaParserConstants.LONGSTRING3, LuaParserConstants.LONGSTRINGN, LuaParserConstants.FALSE, LuaParserConstants.FUNCTION, LuaParserConstants.NIL, LuaParserConstants.NOT, LuaParserConstants.TRUE, LuaParserConstants.NAME, LuaParserConstants.NUMBER, LuaParserConstants.STRING, LuaParserConstants.CHARSTRING, 69, 75, 77, 79, 80, 83 -> {
                l = FieldList()
                c.fields = l
            }
            else -> {
                jj_la1[27] = jj_gen
            }
        }
        jj_consume_token(81)
        L(c, i)
        run { if (true) return c }
        throw Error("Missing return statement in function")
    }


    fun FieldList(): List {
        val l = ArrayList()
        var f: TableField
        f = Field()
        l.add(f)
        label_9@ while (true) {
            if (jj_2_6(2)) {
            } else {
                break@label_9
            }
            FieldSep()
            f = Field()
            l.add(f)
        }
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            70, 72 -> FieldSep()
            else -> {
                jj_la1[28] = jj_gen
            }
        }
        run { if (true) return l }
        throw Error("Missing return statement in function")
    }


    fun Field(): TableField {
        val name: Token
        val exp: Exp
        val rhs: Exp
        val f: TableField
        val i = LineInfo()
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            77 -> {
                jj_consume_token(77)
                exp = Exp()
                jj_consume_token(78)
                jj_consume_token(71)
                rhs = Exp()
                f = TableField.keyedField(exp, rhs)
                L(f, i)
                run { if (true) return f }
            }
            else -> {
                jj_la1[29] = jj_gen
                if (jj_2_7(2)) {
                    name = jj_consume_token(LuaParserConstants.NAME)
                    jj_consume_token(71)
                    rhs = Exp()
                    f = TableField.namedField(name.image!!, rhs)
                    L(f, i)
                    run { if (true) return f }
                } else {
                    when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
                        LuaParserConstants.LONGSTRING0, LuaParserConstants.LONGSTRING1, LuaParserConstants.LONGSTRING2, LuaParserConstants.LONGSTRING3, LuaParserConstants.LONGSTRINGN, LuaParserConstants.FALSE, LuaParserConstants.FUNCTION, LuaParserConstants.NIL, LuaParserConstants.NOT, LuaParserConstants.TRUE, LuaParserConstants.NAME, LuaParserConstants.NUMBER, LuaParserConstants.STRING, LuaParserConstants.CHARSTRING, 69, 75, 79, 80, 83 -> {
                            rhs = Exp()
                            f = TableField.listField(rhs)
                            L(f, i)
                            run { if (true) return f }
                        }
                        else -> {
                            jj_la1[30] = jj_gen
                            jj_consume_token(-1)
                            throw ParseException()
                        }
                    }
                }
            }
        }
        throw Error("Missing return statement in function")
    }


    fun FieldSep() {
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            72 -> jj_consume_token(72)
            70 -> jj_consume_token(70)
            else -> {
                jj_la1[31] = jj_gen
                jj_consume_token(-1)
                throw ParseException()
            }
        }
    }


    fun Binop(): Int {
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            82 -> {
                jj_consume_token(82)
                run { if (true) return Lua.OP_ADD }
            }
            83 -> {
                jj_consume_token(83)
                run { if (true) return Lua.OP_SUB }
            }
            84 -> {
                jj_consume_token(84)
                run { if (true) return Lua.OP_MUL }
            }
            85 -> {
                jj_consume_token(85)
                run { if (true) return Lua.OP_DIV }
            }
            86 -> {
                jj_consume_token(86)
                run { if (true) return Lua.OP_POW }
            }
            87 -> {
                jj_consume_token(87)
                run { if (true) return Lua.OP_MOD }
            }
            88 -> {
                jj_consume_token(88)
                run { if (true) return Lua.OP_CONCAT }
            }
            89 -> {
                jj_consume_token(89)
                run { if (true) return Lua.OP_LT }
            }
            90 -> {
                jj_consume_token(90)
                run { if (true) return Lua.OP_LE }
            }
            91 -> {
                jj_consume_token(91)
                run { if (true) return Lua.OP_GT }
            }
            92 -> {
                jj_consume_token(92)
                run { if (true) return Lua.OP_GE }
            }
            93 -> {
                jj_consume_token(93)
                run { if (true) return Lua.OP_EQ }
            }
            94 -> {
                jj_consume_token(94)
                run { if (true) return Lua.OP_NEQ }
            }
            LuaParserConstants.AND -> {
                jj_consume_token(LuaParserConstants.AND)
                run { if (true) return Lua.OP_AND }
            }
            LuaParserConstants.OR -> {
                jj_consume_token(LuaParserConstants.OR)
                run { if (true) return Lua.OP_OR }
            }
            else -> {
                jj_la1[32] = jj_gen
                jj_consume_token(-1)
                throw ParseException()
            }
        }
        throw Error("Missing return statement in function")
    }


    fun Unop(): Int {
        when (if (jj_ntk == -1) jj_ntk() else jj_ntk) {
            83 -> {
                jj_consume_token(83)
                run { if (true) return Lua.OP_UNM }
            }
            LuaParserConstants.NOT -> {
                jj_consume_token(LuaParserConstants.NOT)
                run { if (true) return Lua.OP_NOT }
            }
            69 -> {
                jj_consume_token(69)
                run { if (true) return Lua.OP_LEN }
            }
            else -> {
                jj_la1[33] = jj_gen
                jj_consume_token(-1)
                throw ParseException()
            }
        }
        throw Error("Missing return statement in function")
    }

    private fun jj_2_1(xla: Int): Boolean {
        jj_la = xla
        jj_scanpos = token
        jj_lastpos = jj_scanpos
        try {
            return !jj_3_1()
        } catch (ls: LookaheadSuccess) {
            return true
        } finally {
            jj_save(0, xla)
        }
    }

    private fun jj_2_2(xla: Int): Boolean {
        jj_la = xla
        jj_scanpos = token
        jj_lastpos = jj_scanpos
        try {
            return !jj_3_2()
        } catch (ls: LookaheadSuccess) {
            return true
        } finally {
            jj_save(1, xla)
        }
    }

    private fun jj_2_3(xla: Int): Boolean {
        jj_la = xla
        jj_scanpos = token
        jj_lastpos = jj_scanpos
        try {
            return !jj_3_3()
        } catch (ls: LookaheadSuccess) {
            return true
        } finally {
            jj_save(2, xla)
        }
    }

    private fun jj_2_4(xla: Int): Boolean {
        jj_la = xla
        jj_scanpos = token
        jj_lastpos = jj_scanpos
        try {
            return !jj_3_4()
        } catch (ls: LookaheadSuccess) {
            return true
        } finally {
            jj_save(3, xla)
        }
    }

    private fun jj_2_5(xla: Int): Boolean {
        jj_la = xla
        jj_scanpos = token
        jj_lastpos = jj_scanpos
        try {
            return !jj_3_5()
        } catch (ls: LookaheadSuccess) {
            return true
        } finally {
            jj_save(4, xla)
        }
    }

    private fun jj_2_6(xla: Int): Boolean {
        jj_la = xla
        jj_scanpos = token
        jj_lastpos = jj_scanpos
        try {
            return !jj_3_6()
        } catch (ls: LookaheadSuccess) {
            return true
        } finally {
            jj_save(5, xla)
        }
    }

    private fun jj_2_7(xla: Int): Boolean {
        jj_la = xla
        jj_scanpos = token
        jj_lastpos = jj_scanpos
        try {
            return !jj_3_7()
        } catch (ls: LookaheadSuccess) {
            return true
        } finally {
            jj_save(6, xla)
        }
    }

    private fun jj_3R_43(): Boolean {
        return if (jj_3R_58()) true else false
    }

    private fun jj_3R_42(): Boolean {
        return if (jj_3R_57()) true else false
    }

    private fun jj_3R_41(): Boolean {
        if (jj_scan_token(75)) return true
        val xsp: Token?
        xsp = jj_scanpos
        if (jj_3R_56()) jj_scanpos = xsp
        return if (jj_scan_token(76)) true else false
    }

    private fun jj_3R_38(): Boolean {
        val xsp: Token?
        xsp = jj_scanpos
        if (jj_3R_41()) {
            jj_scanpos = xsp
            if (jj_3R_42()) {
                jj_scanpos = xsp
                if (jj_3R_43()) return true
            }
        }
        return false
    }

    private fun jj_3_3(): Boolean {
        return if (jj_3R_10()) true else false
    }

    private fun jj_3R_18(): Boolean {
        return if (jj_3R_38()) true else false
    }

    private fun jj_3R_17(): Boolean {
        if (jj_scan_token(74)) return true
        return if (jj_scan_token(LuaParserConstants.NAME)) true else false
    }

    private fun jj_3R_16(): Boolean {
        if (jj_scan_token(77)) return true
        return if (jj_3R_12()) true else false
    }

    private fun jj_3R_35(): Boolean {
        return if (jj_3R_40()) true else false
    }

    private fun jj_3R_15(): Boolean {
        if (jj_scan_token(73)) return true
        return if (jj_scan_token(LuaParserConstants.NAME)) true else false
    }

    private fun jj_3R_10(): Boolean {
        val xsp: Token?
        xsp = jj_scanpos
        if (jj_3R_15()) {
            jj_scanpos = xsp
            if (jj_3R_16()) {
                jj_scanpos = xsp
                if (jj_3R_17()) {
                    jj_scanpos = xsp
                    if (jj_3R_18()) return true
                }
            }
        }
        return false
    }

    private fun jj_3R_59(): Boolean {
        return if (jj_scan_token(LuaParserConstants.FUNCTION)) true else false
    }

    private fun jj_3_5(): Boolean {
        if (jj_3R_11()) return true
        return if (jj_3R_12()) true else false
    }

    private fun jj_3R_60(): Boolean {
        return if (jj_3R_70()) true else false
    }

    private fun jj_3R_55(): Boolean {
        return if (jj_scan_token(69)) true else false
    }

    private fun jj_3R_54(): Boolean {
        return if (jj_scan_token(LuaParserConstants.NOT)) true else false
    }

    private fun jj_3R_53(): Boolean {
        return if (jj_scan_token(83)) true else false
    }

    private fun jj_3R_40(): Boolean {
        val xsp: Token?
        xsp = jj_scanpos
        if (jj_3R_53()) {
            jj_scanpos = xsp
            if (jj_3R_54()) {
                jj_scanpos = xsp
                if (jj_3R_55()) return true
            }
        }
        return false
    }

    private fun jj_3R_34(): Boolean {
        return if (jj_3R_39()) true else false
    }

    private fun jj_3R_12(): Boolean {
        val xsp: Token?
        xsp = jj_scanpos
        if (jj_3R_34()) {
            jj_scanpos = xsp
            if (jj_3R_35()) return true
        }
        return false
    }

    private fun jj_3R_73(): Boolean {
        return if (jj_scan_token(75)) true else false
    }

    private fun jj_3R_33(): Boolean {
        return if (jj_scan_token(LuaParserConstants.OR)) true else false
    }

    private fun jj_3R_72(): Boolean {
        return if (jj_scan_token(LuaParserConstants.NAME)) true else false
    }

    private fun jj_3R_70(): Boolean {
        val xsp: Token?
        xsp = jj_scanpos
        if (jj_3R_72()) {
            jj_scanpos = xsp
            if (jj_3R_73()) return true
        }
        return false
    }

    private fun jj_3_2(): Boolean {
        if (jj_scan_token(LuaParserConstants.LOCAL)) return true
        return if (jj_scan_token(LuaParserConstants.FUNCTION)) true else false
    }

    private fun jj_3R_32(): Boolean {
        return if (jj_scan_token(LuaParserConstants.AND)) true else false
    }

    private fun jj_3R_31(): Boolean {
        return if (jj_scan_token(94)) true else false
    }

    private fun jj_3_4(): Boolean {
        if (jj_scan_token(72)) return true
        return if (jj_scan_token(LuaParserConstants.NAME)) true else false
    }

    private fun jj_3R_30(): Boolean {
        return if (jj_scan_token(93)) true else false
    }

    private fun jj_3_1(): Boolean {
        if (jj_scan_token(LuaParserConstants.FOR)) return true
        if (jj_scan_token(LuaParserConstants.NAME)) return true
        return if (jj_scan_token(71)) true else false
    }

    private fun jj_3R_29(): Boolean {
        return if (jj_scan_token(92)) true else false
    }

    private fun jj_3R_28(): Boolean {
        return if (jj_scan_token(91)) true else false
    }

    private fun jj_3R_69(): Boolean {
        return if (jj_scan_token(LuaParserConstants.LONGSTRINGN)) true else false
    }

    private fun jj_3R_27(): Boolean {
        return if (jj_scan_token(90)) true else false
    }

    private fun jj_3R_68(): Boolean {
        return if (jj_scan_token(LuaParserConstants.LONGSTRING3)) true else false
    }

    private fun jj_3R_26(): Boolean {
        return if (jj_scan_token(89)) true else false
    }

    private fun jj_3R_67(): Boolean {
        return if (jj_scan_token(LuaParserConstants.LONGSTRING2)) true else false
    }

    private fun jj_3R_25(): Boolean {
        return if (jj_scan_token(88)) true else false
    }

    private fun jj_3R_66(): Boolean {
        return if (jj_scan_token(LuaParserConstants.LONGSTRING1)) true else false
    }

    private fun jj_3R_24(): Boolean {
        return if (jj_scan_token(87)) true else false
    }

    private fun jj_3R_65(): Boolean {
        return if (jj_scan_token(LuaParserConstants.LONGSTRING0)) true else false
    }

    private fun jj_3R_23(): Boolean {
        return if (jj_scan_token(86)) true else false
    }

    private fun jj_3R_64(): Boolean {
        return if (jj_scan_token(LuaParserConstants.CHARSTRING)) true else false
    }

    private fun jj_3R_22(): Boolean {
        return if (jj_scan_token(85)) true else false
    }

    private fun jj_3R_63(): Boolean {
        return if (jj_scan_token(LuaParserConstants.STRING)) true else false
    }

    private fun jj_3R_58(): Boolean {
        val xsp: Token?
        xsp = jj_scanpos
        if (jj_3R_63()) {
            jj_scanpos = xsp
            if (jj_3R_64()) {
                jj_scanpos = xsp
                if (jj_3R_65()) {
                    jj_scanpos = xsp
                    if (jj_3R_66()) {
                        jj_scanpos = xsp
                        if (jj_3R_67()) {
                            jj_scanpos = xsp
                            if (jj_3R_68()) {
                                jj_scanpos = xsp
                                if (jj_3R_69()) return true
                            }
                        }
                    }
                }
            }
        }
        return false
    }

    private fun jj_3R_21(): Boolean {
        return if (jj_scan_token(84)) true else false
    }

    private fun jj_3R_20(): Boolean {
        return if (jj_scan_token(83)) true else false
    }

    private fun jj_3R_19(): Boolean {
        return if (jj_scan_token(82)) true else false
    }

    private fun jj_3R_11(): Boolean {
        val xsp: Token?
        xsp = jj_scanpos
        if (jj_3R_19()) {
            jj_scanpos = xsp
            if (jj_3R_20()) {
                jj_scanpos = xsp
                if (jj_3R_21()) {
                    jj_scanpos = xsp
                    if (jj_3R_22()) {
                        jj_scanpos = xsp
                        if (jj_3R_23()) {
                            jj_scanpos = xsp
                            if (jj_3R_24()) {
                                jj_scanpos = xsp
                                if (jj_3R_25()) {
                                    jj_scanpos = xsp
                                    if (jj_3R_26()) {
                                        jj_scanpos = xsp
                                        if (jj_3R_27()) {
                                            jj_scanpos = xsp
                                            if (jj_3R_28()) {
                                                jj_scanpos = xsp
                                                if (jj_3R_29()) {
                                                    jj_scanpos = xsp
                                                    if (jj_3R_30()) {
                                                        jj_scanpos = xsp
                                                        if (jj_3R_31()) {
                                                            jj_scanpos = xsp
                                                            if (jj_3R_32()) {
                                                                jj_scanpos = xsp
                                                                if (jj_3R_33()) return true
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return false
    }

    private fun jj_3_6(): Boolean {
        if (jj_3R_13()) return true
        return if (jj_3R_14()) true else false
    }

    private fun jj_3R_52(): Boolean {
        return if (jj_3R_60()) true else false
    }

    private fun jj_3R_51(): Boolean {
        return if (jj_3R_59()) true else false
    }

    private fun jj_3R_50(): Boolean {
        return if (jj_3R_57()) true else false
    }

    private fun jj_3R_13(): Boolean {
        val xsp: Token?
        xsp = jj_scanpos
        if (jj_scan_token(72)) {
            jj_scanpos = xsp
            if (jj_scan_token(70)) return true
        }
        return false
    }

    private fun jj_3R_49(): Boolean {
        return if (jj_scan_token(79)) true else false
    }

    private fun jj_3R_48(): Boolean {
        return if (jj_3R_58()) true else false
    }

    private fun jj_3R_47(): Boolean {
        return if (jj_scan_token(LuaParserConstants.NUMBER)) true else false
    }

    private fun jj_3R_46(): Boolean {
        return if (jj_scan_token(LuaParserConstants.FALSE)) true else false
    }

    private fun jj_3R_45(): Boolean {
        return if (jj_scan_token(LuaParserConstants.TRUE)) true else false
    }

    private fun jj_3R_44(): Boolean {
        return if (jj_scan_token(LuaParserConstants.NIL)) true else false
    }

    private fun jj_3R_39(): Boolean {
        val xsp: Token?
        xsp = jj_scanpos
        if (jj_3R_44()) {
            jj_scanpos = xsp
            if (jj_3R_45()) {
                jj_scanpos = xsp
                if (jj_3R_46()) {
                    jj_scanpos = xsp
                    if (jj_3R_47()) {
                        jj_scanpos = xsp
                        if (jj_3R_48()) {
                            jj_scanpos = xsp
                            if (jj_3R_49()) {
                                jj_scanpos = xsp
                                if (jj_3R_50()) {
                                    jj_scanpos = xsp
                                    if (jj_3R_51()) {
                                        jj_scanpos = xsp
                                        if (jj_3R_52()) return true
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return false
    }

    private fun jj_3R_37(): Boolean {
        return if (jj_3R_12()) true else false
    }

    private fun jj_3_7(): Boolean {
        if (jj_scan_token(LuaParserConstants.NAME)) return true
        return if (jj_scan_token(71)) true else false
    }

    private fun jj_3R_14(): Boolean {
        val xsp: Token?
        xsp = jj_scanpos
        if (jj_3R_36()) {
            jj_scanpos = xsp
            if (jj_3_7()) {
                jj_scanpos = xsp
                if (jj_3R_37()) return true
            }
        }
        return false
    }

    private fun jj_3R_36(): Boolean {
        return if (jj_scan_token(77)) true else false
    }

    private fun jj_3R_71(): Boolean {
        return if (jj_3R_14()) true else false
    }

    private fun jj_3R_61(): Boolean {
        return if (jj_3R_12()) true else false
    }

    private fun jj_3R_62(): Boolean {
        return if (jj_3R_71()) true else false
    }

    private fun jj_3R_57(): Boolean {
        if (jj_scan_token(80)) return true
        val xsp: Token?
        xsp = jj_scanpos
        if (jj_3R_62()) jj_scanpos = xsp
        return if (jj_scan_token(81)) true else false
    }

    private fun jj_3R_56(): Boolean {
        return if (jj_3R_61()) true else false
    }

    /** Constructor with InputStream and supplied encoding  */
    @JvmOverloads
    constructor(stream: LuaBinInput, encoding: String? = null) {
        charStream = SimpleCharStream(stream, encoding, 1, 1)
        token_source = LuaParserTokenManager(charStream)
        token = Token()
        jj_ntk = -1
        jj_gen = 0
        for (i in 0..33) jj_la1[i] = -1
        for (i in jj_2_rtns.indices) jj_2_rtns[i] = JJCalls()
    }

    /** Reinitialise.  */
    @JvmOverloads
    fun ReInit(stream: LuaBinInput, encoding: String? = null) {
        charStream.ReInit(stream, encoding, 1, 1)
        token_source.ReInit(charStream)
        token = Token()
        jj_ntk = -1
        jj_gen = 0
        for (i in 0..33) jj_la1[i] = -1
        for (i in jj_2_rtns.indices) jj_2_rtns[i] = JJCalls()
    }

    constructor(stream: String) : this(stream.luaReader())

    /** Constructor.  */
    constructor(stream: LuaReader) {
        charStream = SimpleCharStream(stream, 1, 1)
        token_source = LuaParserTokenManager(charStream)
        token = Token()
        jj_ntk = -1
        jj_gen = 0
        for (i in 0..33) jj_la1[i] = -1
        for (i in jj_2_rtns.indices) jj_2_rtns[i] = JJCalls()
    }

    /** Reinitialise.  */
    fun ReInit(stream: LuaReader) {
        charStream.ReInit(stream, 1, 1)
        token_source.ReInit(charStream)
        token = Token()
        jj_ntk = -1
        jj_gen = 0
        for (i in 0..33) jj_la1[i] = -1
        for (i in jj_2_rtns.indices) jj_2_rtns[i] = JJCalls()
    }

    /** Constructor with generated Token Manager.  */
    constructor(tm: LuaParserTokenManager) {
        token_source = tm
        token = Token()
        jj_ntk = -1
        jj_gen = 0
        for (i in 0..33) jj_la1[i] = -1
        for (i in jj_2_rtns.indices) jj_2_rtns[i] = JJCalls()
    }

    /** Reinitialise.  */
    fun ReInit(tm: LuaParserTokenManager) {
        token_source = tm
        token = Token()
        jj_ntk = -1
        jj_gen = 0
        for (i in 0..33) jj_la1[i] = -1
        for (i in jj_2_rtns.indices) jj_2_rtns[i] = JJCalls()
    }


    private fun jj_consume_token(kind: Int): Token {
        val oldToken: Token? = token
        if (oldToken?.next != null)
            token = token!!.next
        else {
            token!!.next = token_source.nextToken
            token = token!!.next
        }
        jj_ntk = -1
        if (token!!.kind == kind) {
            jj_gen++
            if (++jj_gc > 100) {
                jj_gc = 0
                for (i in jj_2_rtns.indices) {
                    var c: JJCalls? = jj_2_rtns[i]
                    while (c != null) {
                        if (c.gen < jj_gen) c.first = null
                        c = c.next
                    }
                }
            }
            return token!!
        }
        token = oldToken
        jj_kind = kind
        throw generateParseException()
    }

    private class LookaheadSuccess : Error()

    private fun jj_scan_token(kind: Int): Boolean {
        if (jj_scanpos == jj_lastpos) {
            jj_la--
            if (jj_scanpos!!.next == null) {
                jj_scanpos!!.next = token_source.nextToken
                jj_scanpos = jj_scanpos!!.next
                jj_lastpos = jj_scanpos
            } else {
                jj_scanpos = jj_scanpos!!.next
                jj_lastpos = jj_scanpos
            }
        } else {
            jj_scanpos = jj_scanpos!!.next
        }
        if (jj_rescan) {
            var i = 0
            var tok = token
            while (tok != null && tok != jj_scanpos) {
                i++
                tok = tok.next
            }
            if (tok != null) jj_add_error_token(kind, i)
        }
        if (jj_scanpos!!.kind != kind) return true
        if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls
        return false
    }

    /** Get the specific Token.  */
    fun getToken(index: Int): Token {
        var t = token
        for (i in 0 until index) {
            if (t!!.next != null)
                t = t.next
            else {
                t.next = token_source.nextToken
                t = t.next
            }
        }
        return t!!
    }

    private fun jj_ntk(): Int {
        if ((run { jj_nt = token!!.next; jj_nt }) == null) {
            token!!.next = token_source.nextToken
            jj_ntk = (token!!.next)!!.kind
        } else {
            jj_ntk = jj_nt!!.kind
        }
        return jj_ntk
    }

    private fun jj_add_error_token(kind: Int, pos: Int) {
        if (pos >= 100) return
        if (pos == jj_endpos + 1) {
            jj_lasttokens[jj_endpos++] = kind
        } else if (jj_endpos != 0) {
            jj_expentry = IntArray(jj_endpos)
            for (i in 0 until jj_endpos) {
                jj_expentry!![i] = jj_lasttokens[i]
            }
            val it = jj_expentries.iterator()
            jj_entries_loop@ while (it.hasNext()) {
                val oldentry = it.next() as IntArray
                if (oldentry.size == jj_expentry!!.size) {
                    for (i in jj_expentry!!.indices) {
                        if (oldentry[i] != jj_expentry!![i]) {
                            continue@jj_entries_loop
                        }
                    }
                    jj_expentries.add(jj_expentry)
                    break@jj_entries_loop
                }
            }
            if (pos != 0) jj_lasttokens[(run { jj_endpos = pos; jj_endpos }) - 1] = kind
        }
    }

    /** Generate ParseException.  */
    fun generateParseException(): ParseException {
        jj_expentries.clear()
        val la1tokens = BooleanArray(95)
        if (jj_kind >= 0) {
            la1tokens[jj_kind] = true
            jj_kind = -1
        }
        for (i in 0..33) {
            if (jj_la1[i] == jj_gen) {
                for (j in 0..31) {
                    if (jj_la1_0!![i] and (1 shl j) != 0) {
                        la1tokens[j] = true
                    }
                    if (jj_la1_1!![i] and (1 shl j) != 0) {
                        la1tokens[32 + j] = true
                    }
                    if (jj_la1_2!![i] and (1 shl j) != 0) {
                        la1tokens[64 + j] = true
                    }
                }
            }
        }
        for (i in 0..94) {
            if (la1tokens[i]) {
                jj_expentry = IntArray(1)
                jj_expentry!![0] = i
                jj_expentries.add(jj_expentry)
            }
        }
        jj_endpos = 0
        jj_rescan_token()
        jj_add_error_token(0, 0)
        val exptokseq = arrayOfNulls(jj_expentries.size)
        for (i in jj_expentries.indices) {
            exptokseq[i] = jj_expentries.get(i) as IntArray
        }
        return ParseException(token!!, exptokseq as Array, LuaParserConstants.tokenImage)
    }

    /** Enable tracing.  */
    fun enable_tracing() {}

    /** Disable tracing.  */
    fun disable_tracing() {}

    private fun jj_rescan_token() {
        jj_rescan = true
        for (i in 0..6) {
            try {
                var p: JJCalls? = jj_2_rtns[i]
                do {
                    if (p!!.gen > jj_gen) {
                        jj_la = p.arg
                        jj_scanpos = p.first
                        jj_lastpos = jj_scanpos
                        when (i) {
                            0 -> jj_3_1()
                            1 -> jj_3_2()
                            2 -> jj_3_3()
                            3 -> jj_3_4()
                            4 -> jj_3_5()
                            5 -> jj_3_6()
                            6 -> jj_3_7()
                        }
                    }
                    p = p.next
                } while (p != null)
            } catch (ls: LookaheadSuccess) {
            }

        }
        jj_rescan = false
    }

    private fun jj_save(index: Int, xla: Int) {
        var p: JJCalls? = jj_2_rtns[index]
        while (p!!.gen > jj_gen) {
            if (p.next == null) {
                p.next = JJCalls()
                p = p.next
                break
            }
            p = p.next
        }
        p.gen = jj_gen + xla - jj_la
        p.first = token
        p.arg = xla
    }

    internal class JJCalls {
        var gen: Int = 0
        var first: Token? = null
        var arg: Int = 0
        var next: JJCalls? = null
    }

    companion object {
        init {
            LuaValue.valueOf(true)
        }



        fun main(args: Array) {
            val parser = LuaParser(JSystem.`in`)
            parser.Chunk()
        }


        private fun assertvarexp(pe: Exp.PrimaryExp): Exp.VarExp {
            if (!pe.isvarexp())
                throw ParseException("expected variable")
            return pe as Exp.VarExp
        }


        private fun assertfunccall(pe: Exp.PrimaryExp): Exp.FuncCall {
            if (!pe.isfunccall())
                throw ParseException("expected function call")
            return pe as Exp.FuncCall
        }

        private var jj_la1_0: IntArray? = null
        private var jj_la1_1: IntArray? = null
        private var jj_la1_2: IntArray? = null

        init {
            jj_la1_init_0()
            jj_la1_init_1()
            jj_la1_init_2()
        }

        private fun jj_la1_init_0() {
            jj_la1_0 = intArrayOf(
                0x0,
                -0x40000000,
                0x0,
                0x0,
                0x0,
                -0x40000000,
                0x0,
                0x0,
                0x0,
                0x0,
                0xf800000,
                0x0,
                0x0,
                0x0,
                0x0,
                0x0,
                0x0,
                0xf800000,
                0xf800000,
                0xf800000,
                0x0,
                0xf800000,
                0xf800000,
                0xf800000,
                0x0,
                0x0,
                0x0,
                0xf800000,
                0x0,
                0x0,
                0xf800000,
                0x0,
                0x20000000,
                0x0
            )
        }

        private fun jj_la1_init_1() {
            jj_la1_1 = intArrayOf(
                0x0,
                0xc42f0,
                0x2000,
                0x0,
                0x0,
                0x440c0,
                0x30,
                0x80200,
                0x2,
                0x1,
                0x60190c28,
                0x0,
                0x0,
                0x0,
                0x0,
                0x0,
                0x80000,
                0x60000000,
                0x60190c28,
                0x60000000,
                0x0,
                0x60190428,
                0x60000000,
                0x60190c28,
                0x80000,
                0x0,
                0x80000,
                0x60190c28,
                0x0,
                0x0,
                0x60190c28,
                0x0,
                0x1000,
                0x800
            )
        }

        private fun jj_la1_init_2() {
            jj_la1_2 = intArrayOf(
                0x20,
                0x842,
                0x0,
                0x100,
                0x80,
                0x42,
                0x0,
                0x800,
                0x0,
                0x0,
                0x98820,
                0x40,
                0x180,
                0x100,
                0x200,
                0x400,
                0x800,
                0x12e00,
                0x98820,
                0x10800,
                0x100,
                0x18800,
                0x0,
                0x98820,
                0x8000,
                0x100,
                0x8000,
                0x9a820,
                0x140,
                0x2000,
                0x98820,
                0x140,
                0x7ffc0000,
                0x80020
            )
        }
    }

}
/** Constructor with InputStream.  */
/** Reinitialise.  */




© 2015 - 2024 Weber Informatics LLC | Privacy Policy