// Code generated by goyacc -o grammar.go grammar.y. DO NOT EDIT.

//line grammar.y:3
package gdb

import __yyfmt__ "fmt"

//line grammar.y:3

const (
	terminator  = "(gdb) " // yes there's the trailing space
	typeKey     = "type"
	classKey    = "class"
	payloadKey  = "payload"
	sequenceKey = "sequence"
)

// avoid DRY due to a poor lexer
func newClassResult(typeString, class string, payload map[string]interface{}) map[string]interface{} {
	out := map[string]interface{}{
		typeKey:  typeString,
		classKey: class,
	}
	if payload != nil {
		out[payloadKey] = payload
	}
	return out
}

//line grammar.y:26
type yySymType struct {
	yys          int
	text         string
	record       map[string]interface{}
	class_result struct {
		class   string
		payload map[string]interface{}
	}
	result_pair struct {
		variable string
		value    interface{}
	}
	value interface{}
	list  []interface{}
}

const text = 57346

var yyToknames = [...]string{
	"$end",
	"error",
	"$unk",
	"text",
	"'*'",
	"'+'",
	"','",
	"'='",
	"'~'",
	"'@'",
	"'&'",
	"'^'",
	"'{'",
	"'}'",
	"'['",
	"']'",
}

var yyStatenames = [...]string{}

const yyEofCode = 1
const yyErrCode = 2
const yyInitialStackSize = 16

//line yacctab:1
var yyExca = [...]int8{
	-1, 1,
	1, -1,
	-2, 0,
}

const yyPrivate = 57344

const yyLast = 59

var yyAct = [...]int8{
	27, 36, 26, 38, 47, 50, 31, 18, 37, 48,
	28, 32, 25, 30, 51, 40, 44, 30, 49, 40,
	20, 22, 23, 31, 28, 24, 28, 19, 21, 29,
	41, 17, 35, 33, 34, 30, 11, 12, 16, 13,
	10, 46, 45, 14, 15, 7, 8, 9, 1, 43,
	52, 53, 42, 39, 5, 4, 3, 2, 6,
}

var yyPact = [...]int16{
	36, -1000, -1000, -1000, -1000, -1000, 31, 40, 34, 27,
	-1000, 23, 24, 23, 23, -1000, -1000, -1000, -1000, 18,
	-1000, 5, -1000, -1000, 6, 22, -1, -1000, 3, -1000,
	20, 6, 4, 16, -1000, -1000, -1000, -1000, -1000, -1000,
	0, -1000, 2, -2, -1000, -1000, -1000, 3, 4, -1000,
	6, -1000, -1000, -1000,
}

var yyPgo = [...]int8{
	0, 58, 2, 57, 56, 55, 54, 3, 7, 0,
	1, 53, 52, 49, 48,
}

var yyR1 = [...]int8{
	0, 14, 3, 3, 3, 4, 4, 4, 4, 8,
	8, 5, 5, 5, 6, 2, 2, 1, 1, 9,
	10, 10, 10, 12, 12, 7, 7, 13, 13, 11,
	11, 11,
}

var yyR2 = [...]int8{
	0, 1, 1, 1, 1, 3, 3, 5, 3, 3,
	1, 2, 2, 2, 3, 3, 1, 0, 1, 3,
	1, 1, 1, 3, 1, 3, 2, 3, 1, 3,
	3, 2,
}

var yyChk = [...]int16{
	-1000, -14, -3, -4, -5, -6, -1, 9, 10, 11,
	4, 5, 6, 8, 12, 4, 4, 4, -8, 4,
	-8, 4, -8, -8, 7, 7, -2, -9, 4, -7,
	13, 7, 8, -2, 14, -9, -10, 4, -7, -11,
	15, 14, -12, -13, 16, -10, -9, 4, 7, 16,
	7, 16, -10, -9,
}

var yyDef = [...]int8{
	17, -2, 1, 2, 3, 4, 0, 0, 0, 0,
	18, 0, 0, 0, 0, 11, 12, 13, 5, 10,
	6, 10, 8, 14, 0, 0, 9, 16, 0, 7,
	0, 0, 0, 0, 26, 15, 19, 20, 21, 22,
	0, 25, 0, 0, 31, 24, 28, 20, 0, 29,
	0, 30, 23, 27,
}

var yyTok1 = [...]int8{
	1, 3, 3, 3, 3, 3, 3, 3, 3, 3,
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
	3, 3, 3, 3, 3, 3, 3, 3, 11, 3,
	3, 3, 5, 6, 7, 3, 3, 3, 3, 3,
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
	3, 8, 3, 3, 10, 3, 3, 3, 3, 3,
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
	3, 15, 3, 16, 12, 3, 3, 3, 3, 3,
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
	3, 3, 3, 13, 3, 14, 9,
}

var yyTok2 = [...]int8{
	2, 3, 4,
}

var yyTok3 = [...]int8{
	0,
}

var yyErrorMessages = [...]struct {
	state int
	token int
	msg   string
}{}

//line yaccpar:1

/*	parser for yacc output	*/

var (
	yyDebug        = 0
	yyErrorVerbose = false
)

type yyLexer interface {
	Lex(lval *yySymType) int
	Error(s string)
}

type yyParser interface {
	Parse(yyLexer) int
	Lookahead() int
}

type yyParserImpl struct {
	lval  yySymType
	stack [yyInitialStackSize]yySymType
	char  int
}

func (p *yyParserImpl) Lookahead() int {
	return p.char
}

func yyNewParser() yyParser {
	return &yyParserImpl{}
}

const yyFlag = -1000

func yyTokname(c int) string {
	if c >= 1 && c-1 < len(yyToknames) {
		if yyToknames[c-1] != "" {
			return yyToknames[c-1]
		}
	}
	return __yyfmt__.Sprintf("tok-%v", c)
}

func yyStatname(s int) string {
	if s >= 0 && s < len(yyStatenames) {
		if yyStatenames[s] != "" {
			return yyStatenames[s]
		}
	}
	return __yyfmt__.Sprintf("state-%v", s)
}

func yyErrorMessage(state, lookAhead int) string {
	const TOKSTART = 4

	if !yyErrorVerbose {
		return "syntax error"
	}

	for _, e := range yyErrorMessages {
		if e.state == state && e.token == lookAhead {
			return "syntax error: " + e.msg
		}
	}

	res := "syntax error: unexpected " + yyTokname(lookAhead)

	// To match Bison, suggest at most four expected tokens.
	expected := make([]int, 0, 4)

	// Look for shiftable tokens.
	base := int(yyPact[state])
	for tok := TOKSTART; tok-1 < len(yyToknames); tok++ {
		if n := base + tok; n >= 0 && n < yyLast && int(yyChk[int(yyAct[n])]) == tok {
			if len(expected) == cap(expected) {
				return res
			}
			expected = append(expected, tok)
		}
	}

	if yyDef[state] == -2 {
		i := 0
		for yyExca[i] != -1 || int(yyExca[i+1]) != state {
			i += 2
		}

		// Look for tokens that we accept or reduce.
		for i += 2; yyExca[i] >= 0; i += 2 {
			tok := int(yyExca[i])
			if tok < TOKSTART || yyExca[i+1] == 0 {
				continue
			}
			if len(expected) == cap(expected) {
				return res
			}
			expected = append(expected, tok)
		}

		// If the default action is to accept or reduce, give up.
		if yyExca[i+1] != 0 {
			return res
		}
	}

	for i, tok := range expected {
		if i == 0 {
			res += ", expecting "
		} else {
			res += " or "
		}
		res += yyTokname(tok)
	}
	return res
}

func yylex1(lex yyLexer, lval *yySymType) (char, token int) {
	token = 0
	char = lex.Lex(lval)
	if char <= 0 {
		token = int(yyTok1[0])
		goto out
	}
	if char < len(yyTok1) {
		token = int(yyTok1[char])
		goto out
	}
	if char >= yyPrivate {
		if char < yyPrivate+len(yyTok2) {
			token = int(yyTok2[char-yyPrivate])
			goto out
		}
	}
	for i := 0; i < len(yyTok3); i += 2 {
		token = int(yyTok3[i+0])
		if token == char {
			token = int(yyTok3[i+1])
			goto out
		}
	}

out:
	if token == 0 {
		token = int(yyTok2[1]) /* unknown char */
	}
	if yyDebug >= 3 {
		__yyfmt__.Printf("lex %s(%d)\n", yyTokname(token), uint(char))
	}
	return char, token
}

func yyParse(yylex yyLexer) int {
	return yyNewParser().Parse(yylex)
}

func (yyrcvr *yyParserImpl) Parse(yylex yyLexer) int {
	var yyn int
	var yyVAL yySymType
	var yyDollar []yySymType
	_ = yyDollar // silence set and not used
	yyS := yyrcvr.stack[:]

	Nerrs := 0   /* number of errors */
	Errflag := 0 /* error recovery flag */
	yystate := 0
	yyrcvr.char = -1
	yytoken := -1 // yyrcvr.char translated into internal numbering
	defer func() {
		// Make sure we report no lookahead when not parsing.
		yystate = -1
		yyrcvr.char = -1
		yytoken = -1
	}()
	yyp := -1
	goto yystack

ret0:
	return 0

ret1:
	return 1

yystack:
	/* put a state and value onto the stack */
	if yyDebug >= 4 {
		__yyfmt__.Printf("char %v in %v\n", yyTokname(yytoken), yyStatname(yystate))
	}

	yyp++
	if yyp >= len(yyS) {
		nyys := make([]yySymType, len(yyS)*2)
		copy(nyys, yyS)
		yyS = nyys
	}
	yyS[yyp] = yyVAL
	yyS[yyp].yys = yystate

yynewstate:
	yyn = int(yyPact[yystate])
	if yyn <= yyFlag {
		goto yydefault /* simple state */
	}
	if yyrcvr.char < 0 {
		yyrcvr.char, yytoken = yylex1(yylex, &yyrcvr.lval)
	}
	yyn += yytoken
	if yyn < 0 || yyn >= yyLast {
		goto yydefault
	}
	yyn = int(yyAct[yyn])
	if int(yyChk[yyn]) == yytoken { /* valid shift */
		yyrcvr.char = -1
		yytoken = -1
		yyVAL = yyrcvr.lval
		yystate = yyn
		if Errflag > 0 {
			Errflag--
		}
		goto yystack
	}

yydefault:
	/* default state action */
	yyn = int(yyDef[yystate])
	if yyn == -2 {
		if yyrcvr.char < 0 {
			yyrcvr.char, yytoken = yylex1(yylex, &yyrcvr.lval)
		}

		/* look through exception table */
		xi := 0
		for {
			if yyExca[xi+0] == -1 && int(yyExca[xi+1]) == yystate {
				break
			}
			xi += 2
		}
		for xi += 2; ; xi += 2 {
			yyn = int(yyExca[xi+0])
			if yyn < 0 || yyn == yytoken {
				break
			}
		}
		yyn = int(yyExca[xi+1])
		if yyn < 0 {
			goto ret0
		}
	}
	if yyn == 0 {
		/* error ... attempt to resume parsing */
		switch Errflag {
		case 0: /* brand new error */
			yylex.Error(yyErrorMessage(yystate, yytoken))
			Nerrs++
			if yyDebug >= 1 {
				__yyfmt__.Printf("%s", yyStatname(yystate))
				__yyfmt__.Printf(" saw %s\n", yyTokname(yytoken))
			}
			fallthrough

		case 1, 2: /* incompletely recovered error ... try again */
			Errflag = 3

			/* find a state where "error" is a legal shift action */
			for yyp >= 0 {
				yyn = int(yyPact[yyS[yyp].yys]) + yyErrCode
				if yyn >= 0 && yyn < yyLast {
					yystate = int(yyAct[yyn]) /* simulate a shift of "error" */
					if int(yyChk[yystate]) == yyErrCode {
						goto yystack
					}
				}

				/* the current p has no shift on "error", pop stack */
				if yyDebug >= 2 {
					__yyfmt__.Printf("error recovery pops state %d\n", yyS[yyp].yys)
				}
				yyp--
			}
			/* there is no state on the stack with an error shift ... abort */
			goto ret1

		case 3: /* no shift yet; clobber input char */
			if yyDebug >= 2 {
				__yyfmt__.Printf("error recovery discards %s\n", yyTokname(yytoken))
			}
			if yytoken == yyEofCode {
				goto ret1
			}
			yyrcvr.char = -1
			yytoken = -1
			goto yynewstate /* try again in the same state */
		}
	}

	/* reduction by production yyn */
	if yyDebug >= 2 {
		__yyfmt__.Printf("reduce %v in:\n\t%v\n", yyn, yyStatname(yystate))
	}

	yynt := yyn
	yypt := yyp
	_ = yypt // guard against "declared and not used"

	yyp -= int(yyR2[yyn])
	// yyp is now the index of $0. Perform the default action. Iff the
	// reduced production is ε, $1 is possibly out of range.
	if yyp+1 >= len(yyS) {
		nyys := make([]yySymType, len(yyS)*2)
		copy(nyys, yyS)
		yyS = nyys
	}
	yyVAL = yyS[yyp+1]

	/* consult goto table to find next state */
	yyn = int(yyR1[yyn])
	yyg := int(yyPgo[yyn])
	yyj := yyg + yyS[yyp].yys + 1

	if yyj >= yyLast {
		yystate = int(yyAct[yyg])
	} else {
		yystate = int(yyAct[yyj])
		if int(yyChk[yystate]) != -yyn {
			yystate = int(yyAct[yyg])
		}
	}
	// dummy call; replaced with literal code
	switch yynt {

	case 1:
		yyDollar = yyS[yypt-1 : yypt+1]
//line grammar.y:47
		{
			yylex.(*parser).output = yyDollar[1].record
		}
	case 5:
		yyDollar = yyS[yypt-3 : yypt+1]
//line grammar.y:55
		{
			yyVAL.record = newClassResult("exec", yyDollar[3].class_result.class, yyDollar[3].class_result.payload)
		}
	case 6:
		yyDollar = yyS[yypt-3 : yypt+1]
//line grammar.y:56
		{
			yyVAL.record = newClassResult("status", yyDollar[3].class_result.class, yyDollar[3].class_result.payload)
		}
	case 7:
		yyDollar = yyS[yypt-5 : yypt+1]
//line grammar.y:57
		{
			yyVAL.record = newClassResult("status", yyDollar[3].text, yyDollar[5].record)
		}
	case 8:
		yyDollar = yyS[yypt-3 : yypt+1]
//line grammar.y:58
		{
			yyVAL.record = newClassResult("notify", yyDollar[3].class_result.class, yyDollar[3].class_result.payload)
		}
	case 9:
		yyDollar = yyS[yypt-3 : yypt+1]
//line grammar.y:61
		{
			yyVAL.class_result.class, yyVAL.class_result.payload = yyDollar[1].text, yyDollar[3].record
		}
	case 10:
		yyDollar = yyS[yypt-1 : yypt+1]
//line grammar.y:62
		{
			yyVAL.class_result.class, yyVAL.class_result.payload = yyDollar[1].text, nil
		}
	case 11:
		yyDollar = yyS[yypt-2 : yypt+1]
//line grammar.y:65
		{
			yyVAL.record = map[string]interface{}{typeKey: "console", payloadKey: yyDollar[2].text}
		}
	case 12:
		yyDollar = yyS[yypt-2 : yypt+1]
//line grammar.y:66
		{
			yyVAL.record = map[string]interface{}{typeKey: "target", payloadKey: yyDollar[2].text}
		}
	case 13:
		yyDollar = yyS[yypt-2 : yypt+1]
//line grammar.y:67
		{
			yyVAL.record = map[string]interface{}{typeKey: "log", payloadKey: yyDollar[2].text}
		}
	case 14:
		yyDollar = yyS[yypt-3 : yypt+1]
//line grammar.y:71
		{
			yyVAL.record = map[string]interface{}{sequenceKey: yyDollar[1].text, classKey: yyDollar[3].class_result.class}
			if yyDollar[3].class_result.payload != nil {
				yyVAL.record[payloadKey] = yyDollar[3].class_result.payload
			}
		}
	case 15:
		yyDollar = yyS[yypt-3 : yypt+1]
//line grammar.y:77
		{
			yyVAL.record[yyDollar[3].result_pair.variable] = yyDollar[3].result_pair.value
		}
	case 16:
		yyDollar = yyS[yypt-1 : yypt+1]
//line grammar.y:78
		{
			yyVAL.record = map[string]interface{}{yyDollar[1].result_pair.variable: yyDollar[1].result_pair.value}
		}
	case 17:
		yyDollar = yyS[yypt-0 : yypt+1]
//line grammar.y:81
		{
			yyVAL.text = ""
		}
	case 18:
		yyDollar = yyS[yypt-1 : yypt+1]
//line grammar.y:82
		{
			yyVAL.text = yyDollar[1].text
		}
	case 19:
		yyDollar = yyS[yypt-3 : yypt+1]
//line grammar.y:85
		{
			yyVAL.result_pair.variable, yyVAL.result_pair.value = yyDollar[1].text, yyDollar[3].value
		}
	case 20:
		yyDollar = yyS[yypt-1 : yypt+1]
//line grammar.y:88
		{
			yyVAL.value = yyDollar[1].text
		}
	case 21:
		yyDollar = yyS[yypt-1 : yypt+1]
//line grammar.y:89
		{
			yyVAL.value = yyDollar[1].record
		}
	case 22:
		yyDollar = yyS[yypt-1 : yypt+1]
//line grammar.y:90
		{
			yyVAL.value = yyDollar[1].list
		}
	case 23:
		yyDollar = yyS[yypt-3 : yypt+1]
//line grammar.y:93
		{
			yyVAL.list = append(yyVAL.list, yyDollar[3].value)
		}
	case 24:
		yyDollar = yyS[yypt-1 : yypt+1]
//line grammar.y:94
		{
			yyVAL.list = []interface{}{yyDollar[1].value}
		}
	case 25:
		yyDollar = yyS[yypt-3 : yypt+1]
//line grammar.y:97
		{
			yyVAL.record = yyDollar[2].record
		}
	case 26:
		yyDollar = yyS[yypt-2 : yypt+1]
//line grammar.y:98
		{
			yyVAL.record = map[string]interface{}{}
		}
	case 27:
		yyDollar = yyS[yypt-3 : yypt+1]
//line grammar.y:101
		{
			yyVAL.list = append(yyVAL.list, map[string]interface{}{yyDollar[3].result_pair.variable: yyDollar[3].result_pair.value})
		}
	case 28:
		yyDollar = yyS[yypt-1 : yypt+1]
//line grammar.y:102
		{
			yyVAL.list = []interface{}{map[string]interface{}{yyDollar[1].result_pair.variable: yyDollar[1].result_pair.value}}
		}
	case 29:
		yyDollar = yyS[yypt-3 : yypt+1]
//line grammar.y:105
		{
			yyVAL.list = yyDollar[2].list
		}
	case 30:
		yyDollar = yyS[yypt-3 : yypt+1]
//line grammar.y:106
		{
			yyVAL.list = yyDollar[2].list
		}
	case 31:
		yyDollar = yyS[yypt-2 : yypt+1]
//line grammar.y:107
		{
			yyVAL.list = []interface{}{}
		}
	}
	goto yystack /* stack new state and value */
}
