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


open SharpSolver.Prelude
open SharpSolver.Prelude.LexYacc
open SharpSolver.Absyn
open SharpSolver.Impl

let neg_monos = List.map monomial_negate


# 17 "Parser.fs"
// This type is the type of tokens accepted by the parser
type token = 
  | EOF
  | VAR
  | PLUS
  | MINUS
  | EQ
  | LT
  | GT
  | LEQ
  | GEQ
  | BRA
  | KET
  | SLASH
  | SQBRA
  | SQKET
  | DERIVE
  | CMD of (string)
  | RATIONAL of (rational)
  | FLOAT of (System.Double)
  | UINT of (System.Int32)
  | APEX of (System.Int32)
// This type is used to give symbolic names to token indexes, useful for error messages
type tokenId = 
    | TOKEN_EOF
    | TOKEN_VAR
    | TOKEN_PLUS
    | TOKEN_MINUS
    | TOKEN_EQ
    | TOKEN_LT
    | TOKEN_GT
    | TOKEN_LEQ
    | TOKEN_GEQ
    | TOKEN_BRA
    | TOKEN_KET
    | TOKEN_SLASH
    | TOKEN_SQBRA
    | TOKEN_SQKET
    | TOKEN_DERIVE
    | TOKEN_CMD
    | TOKEN_RATIONAL
    | TOKEN_FLOAT
    | TOKEN_UINT
    | TOKEN_APEX
    | TOKEN_end_of_input
    | TOKEN_error
// This type is used to give symbolic names to token indexes, useful for error messages
type nonTerminalId = 
    | NONTERM__startline
    | NONTERM_line
    | NONTERM_mono
    | NONTERM_var
    | NONTERM_constant
    | NONTERM_expr
    | NONTERM_monos

// This function maps tokens to integer indexes
let tagOfToken (t:token) = 
  match t with
  | EOF  -> 0 
  | VAR  -> 1 
  | PLUS  -> 2 
  | MINUS  -> 3 
  | EQ  -> 4 
  | LT  -> 5 
  | GT  -> 6 
  | LEQ  -> 7 
  | GEQ  -> 8 
  | BRA  -> 9 
  | KET  -> 10 
  | SLASH  -> 11 
  | SQBRA  -> 12 
  | SQKET  -> 13 
  | DERIVE  -> 14 
  | CMD _ -> 15 
  | RATIONAL _ -> 16 
  | FLOAT _ -> 17 
  | UINT _ -> 18 
  | APEX _ -> 19 

// This function maps integer indexes to symbolic token ids
let tokenTagToTokenId (tokenIdx:int) = 
  match tokenIdx with
  | 0 -> TOKEN_EOF 
  | 1 -> TOKEN_VAR 
  | 2 -> TOKEN_PLUS 
  | 3 -> TOKEN_MINUS 
  | 4 -> TOKEN_EQ 
  | 5 -> TOKEN_LT 
  | 6 -> TOKEN_GT 
  | 7 -> TOKEN_LEQ 
  | 8 -> TOKEN_GEQ 
  | 9 -> TOKEN_BRA 
  | 10 -> TOKEN_KET 
  | 11 -> TOKEN_SLASH 
  | 12 -> TOKEN_SQBRA 
  | 13 -> TOKEN_SQKET 
  | 14 -> TOKEN_DERIVE 
  | 15 -> TOKEN_CMD 
  | 16 -> TOKEN_RATIONAL 
  | 17 -> TOKEN_FLOAT 
  | 18 -> TOKEN_UINT 
  | 19 -> TOKEN_APEX 
  | 22 -> TOKEN_end_of_input
  | 20 -> 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__startline 
    | 1 -> NONTERM_line 
    | 2 -> NONTERM_line 
    | 3 -> NONTERM_line 
    | 4 -> NONTERM_mono 
    | 5 -> NONTERM_mono 
    | 6 -> NONTERM_mono 
    | 7 -> NONTERM_var 
    | 8 -> NONTERM_var 
    | 9 -> NONTERM_var 
    | 10 -> NONTERM_constant 
    | 11 -> NONTERM_constant 
    | 12 -> NONTERM_constant 
    | 13 -> NONTERM_expr 
    | 14 -> NONTERM_expr 
    | 15 -> NONTERM_monos 
    | 16 -> NONTERM_monos 
    | 17 -> NONTERM_monos 
    | 18 -> NONTERM_monos 
    | 19 -> NONTERM_monos 
    | 20 -> NONTERM_monos 
    | _ -> failwith "prodIdxToNonTerminal: bad production index"

let _fsyacc_endOfInputTag = 22 
let _fsyacc_tagOfErrorTerminal = 20

// This function gets the name of a token as a string
let token_to_string (t:token) = 
  match t with 
  | EOF  -> "EOF" 
  | VAR  -> "VAR" 
  | PLUS  -> "PLUS" 
  | MINUS  -> "MINUS" 
  | EQ  -> "EQ" 
  | LT  -> "LT" 
  | GT  -> "GT" 
  | LEQ  -> "LEQ" 
  | GEQ  -> "GEQ" 
  | BRA  -> "BRA" 
  | KET  -> "KET" 
  | SLASH  -> "SLASH" 
  | SQBRA  -> "SQBRA" 
  | SQKET  -> "SQKET" 
  | DERIVE  -> "DERIVE" 
  | CMD _ -> "CMD" 
  | RATIONAL _ -> "RATIONAL" 
  | FLOAT _ -> "FLOAT" 
  | UINT _ -> "UINT" 
  | APEX _ -> "APEX" 

// This function gets the data carried by a token as an object
let _fsyacc_dataOfToken (t:token) = 
  match t with 
  | EOF  -> (null : System.Object) 
  | VAR  -> (null : System.Object) 
  | PLUS  -> (null : System.Object) 
  | MINUS  -> (null : System.Object) 
  | EQ  -> (null : System.Object) 
  | LT  -> (null : System.Object) 
  | GT  -> (null : System.Object) 
  | LEQ  -> (null : System.Object) 
  | GEQ  -> (null : System.Object) 
  | BRA  -> (null : System.Object) 
  | KET  -> (null : System.Object) 
  | SLASH  -> (null : System.Object) 
  | SQBRA  -> (null : System.Object) 
  | SQKET  -> (null : System.Object) 
  | DERIVE  -> (null : System.Object) 
  | CMD _fsyacc_x -> Microsoft.FSharp.Core.Operators.box _fsyacc_x 
  | RATIONAL _fsyacc_x -> Microsoft.FSharp.Core.Operators.box _fsyacc_x 
  | FLOAT _fsyacc_x -> Microsoft.FSharp.Core.Operators.box _fsyacc_x 
  | UINT _fsyacc_x -> Microsoft.FSharp.Core.Operators.box _fsyacc_x 
  | APEX _fsyacc_x -> Microsoft.FSharp.Core.Operators.box _fsyacc_x 
let _fsyacc_gotos = [| 0us; 65535us; 1us; 65535us; 0us; 1us; 8us; 65535us; 0us; 22us; 5us; 22us; 19us; 22us; 23us; 22us; 28us; 29us; 30us; 31us; 32us; 22us; 34us; 22us; 9us; 65535us; 0us; 9us; 5us; 9us; 8us; 10us; 19us; 9us; 23us; 9us; 28us; 9us; 30us; 9us; 32us; 9us; 34us; 9us; 8us; 65535us; 0us; 8us; 5us; 8us; 19us; 8us; 23us; 8us; 28us; 8us; 30us; 8us; 32us; 8us; 34us; 8us; 3us; 65535us; 0us; 3us; 5us; 6us; 19us; 20us; 6us; 65535us; 0us; 17us; 5us; 17us; 19us; 17us; 23us; 24us; 32us; 26us; 34us; 27us; |]
let _fsyacc_sparseGotoTableRowOffsets = [|0us; 1us; 3us; 12us; 22us; 31us; 35us; |]
let _fsyacc_stateToProdIdxsTableElements = [| 1us; 0us; 1us; 0us; 1us; 1us; 2us; 2us; 3us; 1us; 2us; 1us; 3us; 1us; 3us; 1us; 3us; 2us; 4us; 6us; 1us; 5us; 1us; 6us; 3us; 7us; 8us; 9us; 1us; 8us; 1us; 9us; 1us; 10us; 1us; 11us; 1us; 12us; 4us; 13us; 17us; 18us; 19us; 1us; 14us; 1us; 14us; 1us; 14us; 1us; 14us; 1us; 15us; 1us; 16us; 4us; 16us; 17us; 18us; 19us; 1us; 16us; 4us; 17us; 18us; 19us; 19us; 4us; 17us; 18us; 19us; 20us; 1us; 17us; 1us; 17us; 2us; 18us; 19us; 1us; 18us; 1us; 19us; 1us; 19us; 1us; 20us; |]
let _fsyacc_stateToProdIdxsTableRowOffsets = [|0us; 2us; 4us; 6us; 9us; 11us; 13us; 15us; 17us; 20us; 22us; 24us; 28us; 30us; 32us; 34us; 36us; 38us; 43us; 45us; 47us; 49us; 51us; 53us; 55us; 60us; 62us; 67us; 72us; 74us; 76us; 79us; 81us; 83us; 85us; |]
let _fsyacc_action_rows = 35
let _fsyacc_actionTableElements = [|8us; 32768us; 1us; 11us; 3us; 34us; 9us; 23us; 14us; 18us; 15us; 2us; 16us; 16us; 17us; 15us; 18us; 14us; 0us; 49152us; 0us; 16385us; 2us; 32768us; 0us; 4us; 4us; 5us; 0us; 16386us; 7us; 32768us; 1us; 11us; 3us; 34us; 9us; 23us; 14us; 18us; 16us; 16us; 17us; 15us; 18us; 14us; 1us; 32768us; 0us; 7us; 0us; 16387us; 1us; 16388us; 1us; 11us; 0us; 16389us; 0us; 16390us; 2us; 16391us; 18us; 13us; 19us; 12us; 0us; 16392us; 0us; 16393us; 0us; 16394us; 0us; 16395us; 0us; 16396us; 2us; 16397us; 2us; 28us; 3us; 30us; 1us; 32768us; 12us; 19us; 7us; 32768us; 1us; 11us; 3us; 34us; 9us; 23us; 14us; 18us; 16us; 16us; 17us; 15us; 18us; 14us; 1us; 32768us; 13us; 21us; 0us; 16398us; 0us; 16399us; 6us; 32768us; 1us; 11us; 3us; 34us; 9us; 23us; 16us; 16us; 17us; 15us; 18us; 14us; 3us; 32768us; 2us; 28us; 3us; 30us; 10us; 25us; 0us; 16400us; 3us; 32768us; 2us; 28us; 3us; 30us; 10us; 33us; 0us; 16404us; 4us; 32768us; 1us; 11us; 16us; 16us; 17us; 15us; 18us; 14us; 0us; 16401us; 5us; 32768us; 1us; 11us; 9us; 32us; 16us; 16us; 17us; 15us; 18us; 14us; 0us; 16402us; 6us; 32768us; 1us; 11us; 3us; 34us; 9us; 23us; 16us; 16us; 17us; 15us; 18us; 14us; 0us; 16403us; 6us; 32768us; 1us; 11us; 3us; 34us; 9us; 23us; 16us; 16us; 17us; 15us; 18us; 14us; |]
let _fsyacc_actionTableRowOffsets = [|0us; 9us; 10us; 11us; 14us; 15us; 23us; 25us; 26us; 28us; 29us; 30us; 33us; 34us; 35us; 36us; 37us; 38us; 41us; 43us; 51us; 53us; 54us; 55us; 62us; 66us; 67us; 71us; 72us; 77us; 78us; 84us; 85us; 92us; 93us; |]
let _fsyacc_reductionSymbolCounts = [|1us; 1us; 2us; 4us; 1us; 1us; 2us; 1us; 2us; 2us; 1us; 1us; 1us; 1us; 4us; 1us; 3us; 3us; 3us; 5us; 2us; |]
let _fsyacc_productionToNonTerminalTable = [|0us; 1us; 1us; 1us; 2us; 2us; 2us; 3us; 3us; 3us; 4us; 4us; 4us; 5us; 5us; 6us; 6us; 6us; 6us; 6us; 6us; |]
let _fsyacc_immediateActions = [|65535us; 49152us; 16385us; 65535us; 16386us; 65535us; 65535us; 16387us; 65535us; 16389us; 16390us; 65535us; 16392us; 16393us; 16394us; 16395us; 16396us; 65535us; 65535us; 65535us; 65535us; 16398us; 16399us; 65535us; 65535us; 16400us; 65535us; 65535us; 65535us; 16401us; 65535us; 16402us; 65535us; 16403us; 65535us; |]
let _fsyacc_reductions ()  =    [| 
# 212 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data :  line )) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
                      raise (Microsoft.FSharp.Text.Parsing.Accept(Microsoft.FSharp.Core.Operators.box _1))
                   )
                 : '_startline));
# 221 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : string)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 36 "Parser.fsy"
                                  Cmd _1 
                   )
# 36 "Parser.fsy"
                 :  line ));
# 232 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : 'expr)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 37 "Parser.fsy"
                                                 Expr _1 
                   )
# 37 "Parser.fsy"
                 :  line ));
# 243 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : 'expr)) in
            let _3 = (let data = parseState.GetInput(3) in (Microsoft.FSharp.Core.Operators.unbox data : 'expr)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 38 "Parser.fsy"
                                                       Equ (_1, _3) 
                   )
# 38 "Parser.fsy"
                 :  line ));
# 255 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : 'constant)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 41 "Parser.fsy"
                                                       Monomial (_1, 0) 
                   )
# 41 "Parser.fsy"
                 : 'mono));
# 266 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : 'var)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 42 "Parser.fsy"
                                                       Monomial (1Q, _1) 
                   )
# 42 "Parser.fsy"
                 : 'mono));
# 277 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : 'constant)) in
            let _2 = (let data = parseState.GetInput(2) in (Microsoft.FSharp.Core.Operators.unbox data : 'var)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 43 "Parser.fsy"
                                                       Monomial (_1, _2) 
                   )
# 43 "Parser.fsy"
                 : 'mono));
# 289 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 46 "Parser.fsy"
                                                       1 
                   )
# 46 "Parser.fsy"
                 : 'var));
# 299 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _2 = (let data = parseState.GetInput(2) in (Microsoft.FSharp.Core.Operators.unbox data : System.Int32)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 47 "Parser.fsy"
                                                       _2 
                   )
# 47 "Parser.fsy"
                 : 'var));
# 310 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _2 = (let data = parseState.GetInput(2) in (Microsoft.FSharp.Core.Operators.unbox data : System.Int32)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 48 "Parser.fsy"
                                                       _2 
                   )
# 48 "Parser.fsy"
                 : 'var));
# 321 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : System.Int32)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 51 "Parser.fsy"
                                                       rational _1 
                   )
# 51 "Parser.fsy"
                 : 'constant));
# 332 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : System.Double)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 52 "Parser.fsy"
                                                       rationalize _1 
                   )
# 52 "Parser.fsy"
                 : 'constant));
# 343 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : rational)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 53 "Parser.fsy"
                                                       _1 
                   )
# 53 "Parser.fsy"
                 : 'constant));
# 354 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : 'monos)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 56 "Parser.fsy"
                                                       Poly (Polynomial _1) 
                   )
# 56 "Parser.fsy"
                 : 'expr));
# 365 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _3 = (let data = parseState.GetInput(3) in (Microsoft.FSharp.Core.Operators.unbox data : 'expr)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 57 "Parser.fsy"
                                                    Derive _3 
                   )
# 57 "Parser.fsy"
                 : 'expr));
# 376 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : 'mono)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 60 "Parser.fsy"
                                       [_1] 
                   )
# 60 "Parser.fsy"
                 : 'monos));
# 387 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _2 = (let data = parseState.GetInput(2) in (Microsoft.FSharp.Core.Operators.unbox data : 'monos)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 61 "Parser.fsy"
                                              _2 
                   )
# 61 "Parser.fsy"
                 : 'monos));
# 398 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : 'monos)) in
            let _3 = (let data = parseState.GetInput(3) in (Microsoft.FSharp.Core.Operators.unbox data : 'mono)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 62 "Parser.fsy"
                                                _1 @ [_3] 
                   )
# 62 "Parser.fsy"
                 : 'monos));
# 410 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : 'monos)) in
            let _3 = (let data = parseState.GetInput(3) in (Microsoft.FSharp.Core.Operators.unbox data : 'mono)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 63 "Parser.fsy"
                                                _1 @ [monomial_negate _3] 
                   )
# 63 "Parser.fsy"
                 : 'monos));
# 422 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _1 = (let data = parseState.GetInput(1) in (Microsoft.FSharp.Core.Operators.unbox data : 'monos)) in
            let _4 = (let data = parseState.GetInput(4) in (Microsoft.FSharp.Core.Operators.unbox data : 'monos)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 64 "Parser.fsy"
                                                       _1 @ neg_monos _4 
                   )
# 64 "Parser.fsy"
                 : 'monos));
# 434 "Parser.fs"
        (fun (parseState : Microsoft.FSharp.Text.Parsing.IParseState) ->
            let _2 = (let data = parseState.GetInput(2) in (Microsoft.FSharp.Core.Operators.unbox data : 'monos)) in
            Microsoft.FSharp.Core.Operators.box
                (
                   (
# 65 "Parser.fsy"
                                                      neg_monos _2 
                   )
# 65 "Parser.fsy"
                 : 'monos));
|]
# 446 "Parser.fs"
let tables () : Microsoft.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:Microsoft.FSharp.Text.Parsing.ParseErrorContext<_>) -> 
                              match parse_error_rich with 
                              | Some f -> f ctxt
                              | None -> parse_error ctxt.Message);
    numTerminals = 23;
    productionToNonTerminalTable = _fsyacc_productionToNonTerminalTable  }
let engine lexer lexbuf startState = (tables ()).Interpret(lexer, lexbuf, startState)
let line lexer lexbuf :  line  =
    Microsoft.FSharp.Core.Operators.unbox ((tables ()).Interpret(lexer, lexbuf, 0))
