// Implementation file for parser generated by fsyacc
module Parser
#nowarn "64";; // turn off warnings that type variables used in production annotations are instantiated to concrete type
open FSharp.Text.Lexing
open FSharp.Text.Parsing.ParseHelpers
# 1 "Parser.fsp"

open FSharp.Text.Parsing

# 10 "Parser.fs"
// This type is the type of tokens accepted by the parser
type token = 
  | SUM
  | PROD
  | MAX
  | ARGMAX
  | PLUS
  | MINUS
  | TIMES
  | LET
  | IN
  | TO
  | OF
  | EOF
  | LPAR
  | RPAR
  | EQ
  | VAR of (string)
  | INT of (int)
// This type is used to give symbolic names to token indexes, useful for error messages
type tokenId = 
    | TOKEN_SUM
    | TOKEN_PROD
    | TOKEN_MAX
    | TOKEN_ARGMAX
    | TOKEN_PLUS
    | TOKEN_MINUS
    | TOKEN_TIMES
    | TOKEN_LET
    | TOKEN_IN
    | TOKEN_TO
    | TOKEN_OF
    | TOKEN_EOF
    | TOKEN_LPAR
    | TOKEN_RPAR
    | TOKEN_EQ
    | TOKEN_VAR
    | TOKEN_INT
    | TOKEN_end_of_input
    | TOKEN_error
// This type is used to give symbolic names to token indexes, useful for error messages
type nonTerminalId = 
    | NONTERM__startProg
    | NONTERM_Prog
    | NONTERM_Exp

// This function maps tokens to integer indexes
let tagOfToken (t:token) = 
  match t with
  | SUM  -> 0 
  | PROD  -> 1 
  | MAX  -> 2 
  | ARGMAX  -> 3 
  | PLUS  -> 4 
  | MINUS  -> 5 
  | TIMES  -> 6 
  | LET  -> 7 
  | IN  -> 8 
  | TO  -> 9 
  | OF  -> 10 
  | EOF  -> 11 
  | LPAR  -> 12 
  | RPAR  -> 13 
  | EQ  -> 14 
  | VAR _ -> 15 
  | INT _ -> 16 

// This function maps integer indexes to symbolic token ids
let tokenTagToTokenId (tokenIdx:int) = 
  match tokenIdx with
  | 0 -> TOKEN_SUM 
  | 1 -> TOKEN_PROD 
  | 2 -> TOKEN_MAX 
  | 3 -> TOKEN_ARGMAX 
  | 4 -> TOKEN_PLUS 
  | 5 -> TOKEN_MINUS 
  | 6 -> TOKEN_TIMES 
  | 7 -> TOKEN_LET 
  | 8 -> TOKEN_IN 
  | 9 -> TOKEN_TO 
  | 10 -> TOKEN_OF 
  | 11 -> TOKEN_EOF 
  | 12 -> TOKEN_LPAR 
  | 13 -> TOKEN_RPAR 
  | 14 -> TOKEN_EQ 
  | 15 -> TOKEN_VAR 
  | 16 -> TOKEN_INT 
  | 19 -> TOKEN_end_of_input
  | 17 -> TOKEN_error
  | _ -> failwith "tokenTagToTokenId: bad token"

/// This function maps production indexes returned in syntax errors to strings representing the non terminal that would be produced by that production
let prodIdxToNonTerminal (prodIdx:int) = 
  match prodIdx with
    | 0 -> NONTERM__startProg 
    | 1 -> NONTERM_Prog 
    | 2 -> NONTERM_Exp 
    | 3 -> NONTERM_Exp 
    | 4 -> NONTERM_Exp 
    | 5 -> NONTERM_Exp 
    | 6 -> NONTERM_Exp 
    | 7 -> NONTERM_Exp 
    | 8 -> NONTERM_Exp 
    | 9 -> NONTERM_Exp 
    | 10 -> NONTERM_Exp 
    | 11 -> NONTERM_Exp 
    | 12 -> NONTERM_Exp 
    | _ -> failwith "prodIdxToNonTerminal: bad production index"

let _fsyacc_endOfInputTag = 19 
let _fsyacc_tagOfErrorTerminal = 17

// This function gets the name of a token as a string
let token_to_string (t:token) = 
  match t with 
  | SUM  -> "SUM" 
  | PROD  -> "PROD" 
  | MAX  -> "MAX" 
  | ARGMAX  -> "ARGMAX" 
  | PLUS  -> "PLUS" 
  | MINUS  -> "MINUS" 
  | TIMES  -> "TIMES" 
  | LET  -> "LET" 
  | IN  -> "IN" 
  | TO  -> "TO" 
  | OF  -> "OF" 
  | EOF  -> "EOF" 
  | LPAR  -> "LPAR" 
  | RPAR  -> "RPAR" 
  | EQ  -> "EQ" 
  | VAR _ -> "VAR" 
  | INT _ -> "INT" 

// This function gets the data carried by a token as an object
let _fsyacc_dataOfToken (t:token) = 
  match t with 
  | SUM  -> (null : System.Object) 
  | PROD  -> (null : System.Object) 
  | MAX  -> (null : System.Object) 
  | ARGMAX  -> (null : System.Object) 
  | PLUS  -> (null : System.Object) 
  | MINUS  -> (null : System.Object) 
  | TIMES  -> (null : System.Object) 
  | LET  -> (null : System.Object) 
  | IN  -> (null : System.Object) 
  | TO  -> (null : System.Object) 
  | OF  -> (null : System.Object) 
  | EOF  -> (null : System.Object) 
  | LPAR  -> (null : System.Object) 
  | RPAR  -> (null : System.Object) 
  | EQ  -> (null : System.Object) 
  | VAR _fsyacc_x -> Microsoft.FSharp.Core.Operators.box _fsyacc_x 
  | INT _fsyacc_x -> Microsoft.FSharp.Core.Operators.box _fsyacc_x 
let _fsyacc_gotos = [| 0us; 65535us; 1us; 65535us; 0us; 1us; 19us; 65535us; 0us; 2us; 6us; 7us; 26us; 9us; 27us; 10us; 28us; 11us; 31us; 12us; 32us; 13us; 35us; 14us; 36us; 15us; 37us; 16us; 40us; 17us; 41us; 18us; 42us; 19us; 45us; 20us; 46us; 21us; 47us; 22us; 50us; 23us; 51us; 24us; 52us; 25us; |]
let _fsyacc_sparseGotoTableRowOffsets = [|0us; 1us; 3us; |]
let _fsyacc_stateToProdIdxsTableElements = [| 1us; 0us; 1us; 0us; 4us; 1us; 5us; 6us; 7us; 1us; 1us; 1us; 2us; 1us; 3us; 1us; 4us; 4us; 4us; 5us; 6us; 7us; 1us; 4us; 4us; 5us; 5us; 6us; 7us; 4us; 5us; 6us; 6us; 7us; 4us; 5us; 6us; 7us; 7us; 4us; 5us; 6us; 7us; 8us; 4us; 5us; 6us; 7us; 8us; 4us; 5us; 6us; 7us; 9us; 4us; 5us; 6us; 7us; 9us; 4us; 5us; 6us; 7us; 9us; 4us; 5us; 6us; 7us; 10us; 4us; 5us; 6us; 7us; 10us; 4us; 5us; 6us; 7us; 10us; 4us; 5us; 6us; 7us; 11us; 4us; 5us; 6us; 7us; 11us; 4us; 5us; 6us; 7us; 11us; 4us; 5us; 6us; 7us; 12us; 4us; 5us; 6us; 7us; 12us; 4us; 5us; 6us; 7us; 12us; 1us; 5us; 1us; 6us; 1us; 7us; 1us; 8us; 1us; 8us; 1us; 8us; 1us; 8us; 1us; 9us; 1us; 9us; 1us; 9us; 1us; 9us; 1us; 9us; 1us; 10us; 1us; 10us; 1us; 10us; 1us; 10us; 1us; 10us; 1us; 11us; 1us; 11us; 1us; 11us; 1us; 11us; 1us; 11us; 1us; 12us; 1us; 12us; 1us; 12us; 1us; 12us; 1us; 12us; |]
let _fsyacc_stateToProdIdxsTableRowOffsets = [|0us; 2us; 4us; 9us; 11us; 13us; 15us; 17us; 22us; 24us; 29us; 34us; 39us; 44us; 49us; 54us; 59us; 64us; 69us; 74us; 79us; 84us; 89us; 94us; 99us; 104us; 109us; 111us; 113us; 115us; 117us; 119us; 121us; 123us; 125us; 127us; 129us; 131us; 133us; 135us; 137us; 139us; 141us; 143us; 145us; 147us; 149us; 151us; 153us; 155us; 157us; 159us; 161us; |]
let _fsyacc_action_rows = 53
let _fsyacc_actionTableElements = [|8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 0us; 49152us; 4us; 32768us; 4us; 26us; 5us; 27us; 6us; 28us; 11us; 3us; 0us; 16385us; 0us; 16386us; 0us; 16387us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 4us; 32768us; 4us; 26us; 5us; 27us; 6us; 28us; 13us; 8us; 0us; 16388us; 1us; 16389us; 6us; 28us; 1us; 16390us; 6us; 28us; 0us; 16391us; 4us; 32768us; 4us; 26us; 5us; 27us; 6us; 28us; 8us; 32us; 3us; 16392us; 4us; 26us; 5us; 27us; 6us; 28us; 4us; 32768us; 4us; 26us; 5us; 27us; 6us; 28us; 9us; 36us; 4us; 32768us; 4us; 26us; 5us; 27us; 6us; 28us; 10us; 37us; 3us; 16393us; 4us; 26us; 5us; 27us; 6us; 28us; 4us; 32768us; 4us; 26us; 5us; 27us; 6us; 28us; 9us; 41us; 4us; 32768us; 4us; 26us; 5us; 27us; 6us; 28us; 10us; 42us; 3us; 16394us; 4us; 26us; 5us; 27us; 6us; 28us; 4us; 32768us; 4us; 26us; 5us; 27us; 6us; 28us; 9us; 46us; 4us; 32768us; 4us; 26us; 5us; 27us; 6us; 28us; 10us; 47us; 3us; 16395us; 4us; 26us; 5us; 27us; 6us; 28us; 4us; 32768us; 4us; 26us; 5us; 27us; 6us; 28us; 9us; 51us; 4us; 32768us; 4us; 26us; 5us; 27us; 6us; 28us; 10us; 52us; 3us; 16396us; 4us; 26us; 5us; 27us; 6us; 28us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 1us; 32768us; 15us; 30us; 1us; 32768us; 14us; 31us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 1us; 32768us; 15us; 34us; 1us; 32768us; 14us; 35us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 1us; 32768us; 15us; 39us; 1us; 32768us; 14us; 40us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 1us; 32768us; 15us; 44us; 1us; 32768us; 14us; 45us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 1us; 32768us; 15us; 49us; 1us; 32768us; 14us; 50us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; 8us; 32768us; 0us; 33us; 1us; 38us; 2us; 43us; 3us; 48us; 7us; 29us; 12us; 6us; 15us; 5us; 16us; 4us; |]
let _fsyacc_actionTableRowOffsets = [|0us; 9us; 10us; 15us; 16us; 17us; 18us; 27us; 32us; 33us; 35us; 37us; 38us; 43us; 47us; 52us; 57us; 61us; 66us; 71us; 75us; 80us; 85us; 89us; 94us; 99us; 103us; 112us; 121us; 130us; 132us; 134us; 143us; 152us; 154us; 156us; 165us; 174us; 183us; 185us; 187us; 196us; 205us; 214us; 216us; 218us; 227us; 236us; 245us; 247us; 249us; 258us; 267us; |]
let _fsyacc_reductionSymbolCounts = [|1us; 2us; 1us; 1us; 3us; 3us; 3us; 3us; 6us; 8us; 8us; 8us; 8us; |]
let _fsyacc_productionToNonTerminalTable = [|0us; 1us; 2us; 2us; 2us; 2us; 2us; 2us; 2us; 2us; 2us; 2us; 2us; |]
let _fsyacc_immediateActions = [|65535us; 49152us; 65535us; 16385us; 16386us; 16387us; 65535us; 65535us; 16388us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; 65535us; |]
let _fsyacc_reductions ()  =    [| 
# 175 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _1 = parseState.GetInput(1) :?> AbSyn.EXP in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
                      raise (FSharp.Text.Parsing.Accept(Microsoft.FSharp.Core.Operators.box _1))
                   )
                 : 'gentype__startProg));
# 184 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _1 = parseState.GetInput(1) :?> AbSyn.EXP in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 30 "Parser.fsp"
                                      _1 
                   )
# 30 "Parser.fsp"
                 : AbSyn.EXP));
# 195 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _1 = parseState.GetInput(1) :?> int in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 33 "Parser.fsp"
                                                                               AbSyn.CONSTANT (AbSyn.INT _1) 
                   )
# 33 "Parser.fsp"
                 : AbSyn.EXP));
# 206 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _1 = parseState.GetInput(1) :?> string in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 34 "Parser.fsp"
                                                                               AbSyn.VARIABLE _1 
                   )
# 34 "Parser.fsp"
                 : AbSyn.EXP));
# 217 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _2 = parseState.GetInput(2) :?> AbSyn.EXP in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 35 "Parser.fsp"
                                                                               _2 
                   )
# 35 "Parser.fsp"
                 : AbSyn.EXP));
# 228 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _1 = parseState.GetInput(1) :?> AbSyn.EXP in
            let _3 = parseState.GetInput(3) :?> AbSyn.EXP in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 36 "Parser.fsp"
                                                                               AbSyn.OPERATE (AbSyn.BPLUS, _1, _3) 
                   )
# 36 "Parser.fsp"
                 : AbSyn.EXP));
# 240 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _1 = parseState.GetInput(1) :?> AbSyn.EXP in
            let _3 = parseState.GetInput(3) :?> AbSyn.EXP in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 37 "Parser.fsp"
                                                                               AbSyn.OPERATE (AbSyn.BMINUS, _1, _3) 
                   )
# 37 "Parser.fsp"
                 : AbSyn.EXP));
# 252 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _1 = parseState.GetInput(1) :?> AbSyn.EXP in
            let _3 = parseState.GetInput(3) :?> AbSyn.EXP in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 38 "Parser.fsp"
                                                                               AbSyn.OPERATE (AbSyn.BTIMES, _1, _3) 
                   )
# 38 "Parser.fsp"
                 : AbSyn.EXP));
# 264 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _2 = parseState.GetInput(2) :?> string in
            let _4 = parseState.GetInput(4) :?> AbSyn.EXP in
            let _6 = parseState.GetInput(6) :?> AbSyn.EXP in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 39 "Parser.fsp"
                                                                               AbSyn.LET_IN (_2, _4, _6) 
                   )
# 39 "Parser.fsp"
                 : AbSyn.EXP));
# 277 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _2 = parseState.GetInput(2) :?> string in
            let _4 = parseState.GetInput(4) :?> AbSyn.EXP in
            let _6 = parseState.GetInput(6) :?> AbSyn.EXP in
            let _8 = parseState.GetInput(8) :?> AbSyn.EXP in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 40 "Parser.fsp"
                                                                               AbSyn.OVER (AbSyn.RSUM, _2, _4, _6, _8) 
                   )
# 40 "Parser.fsp"
                 : AbSyn.EXP));
# 291 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _2 = parseState.GetInput(2) :?> string in
            let _4 = parseState.GetInput(4) :?> AbSyn.EXP in
            let _6 = parseState.GetInput(6) :?> AbSyn.EXP in
            let _8 = parseState.GetInput(8) :?> AbSyn.EXP in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 41 "Parser.fsp"
                                                                               AbSyn.OVER (AbSyn.RPROD, _2, _4, _6, _8) 
                   )
# 41 "Parser.fsp"
                 : AbSyn.EXP));
# 305 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _2 = parseState.GetInput(2) :?> string in
            let _4 = parseState.GetInput(4) :?> AbSyn.EXP in
            let _6 = parseState.GetInput(6) :?> AbSyn.EXP in
            let _8 = parseState.GetInput(8) :?> AbSyn.EXP in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 42 "Parser.fsp"
                                                                               AbSyn.OVER (AbSyn.RMAX, _2, _4, _6, _8) 
                   )
# 42 "Parser.fsp"
                 : AbSyn.EXP));
# 319 "Parser.fs"
        (fun (parseState : FSharp.Text.Parsing.IParseState) ->
            let _2 = parseState.GetInput(2) :?> string in
            let _4 = parseState.GetInput(4) :?> AbSyn.EXP in
            let _6 = parseState.GetInput(6) :?> AbSyn.EXP in
            let _8 = parseState.GetInput(8) :?> AbSyn.EXP in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 43 "Parser.fsp"
                                                                               AbSyn.OVER (AbSyn.RARGMAX, _2, _4, _6, _8) 
                   )
# 43 "Parser.fsp"
                 : AbSyn.EXP));
|]
# 334 "Parser.fs"
let tables : FSharp.Text.Parsing.Tables<_> = 
  { reductions= _fsyacc_reductions ();
    endOfInputTag = _fsyacc_endOfInputTag;
    tagOfToken = tagOfToken;
    dataOfToken = _fsyacc_dataOfToken; 
    actionTableElements = _fsyacc_actionTableElements;
    actionTableRowOffsets = _fsyacc_actionTableRowOffsets;
    stateToProdIdxsTableElements = _fsyacc_stateToProdIdxsTableElements;
    stateToProdIdxsTableRowOffsets = _fsyacc_stateToProdIdxsTableRowOffsets;
    reductionSymbolCounts = _fsyacc_reductionSymbolCounts;
    immediateActions = _fsyacc_immediateActions;
    gotos = _fsyacc_gotos;
    sparseGotoTableRowOffsets = _fsyacc_sparseGotoTableRowOffsets;
    tagOfErrorTerminal = _fsyacc_tagOfErrorTerminal;
    parseError = (fun (ctxt:FSharp.Text.Parsing.ParseErrorContext<_>) -> 
                              match parse_error_rich with 
                              | Some f -> f ctxt
                              | None -> parse_error ctxt.Message);
    numTerminals = 20;
    productionToNonTerminalTable = _fsyacc_productionToNonTerminalTable  }
let engine lexer lexbuf startState = tables.Interpret(lexer, lexbuf, startState)
let Prog lexer lexbuf : AbSyn.EXP =
    engine lexer lexbuf 0 :?> _
