Files
control-see/ldtext/Parser.fs

223 lines
8.1 KiB
Forth

// 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.fsy"
open LDText.Ast
open FSharp.Text.Lexing
# 11 "Parser.fs"
// This type is the type of tokens accepted by the parser
type token =
| EOF
| QUESTION_MARK
| SEMICOLON
| COMMA
| RIGHT_BRACKET
| LEFT_BRACKET
| RIGHT_PAREN
| LEFT_PAREN
| IDENTIFIER of (string)
// This type is used to give symbolic names to token indexes, useful for error messages
type tokenId =
| TOKEN_EOF
| TOKEN_QUESTION_MARK
| TOKEN_SEMICOLON
| TOKEN_COMMA
| TOKEN_RIGHT_BRACKET
| TOKEN_LEFT_BRACKET
| TOKEN_RIGHT_PAREN
| TOKEN_LEFT_PAREN
| TOKEN_IDENTIFIER
| TOKEN_end_of_input
| TOKEN_error
// This type is used to give symbolic names to token indexes, useful for error messages
type nonTerminalId =
| NONTERM__startinstr
| NONTERM_instr
| NONTERM_operands
| NONTERM_operand
// This function maps tokens to integer indexes
let tagOfToken (t:token) =
match t with
| EOF -> 0
| QUESTION_MARK -> 1
| SEMICOLON -> 2
| COMMA -> 3
| RIGHT_BRACKET -> 4
| LEFT_BRACKET -> 5
| RIGHT_PAREN -> 6
| LEFT_PAREN -> 7
| IDENTIFIER _ -> 8
// This function maps integer indexes to symbolic token ids
let tokenTagToTokenId (tokenIdx:int) =
match tokenIdx with
| 0 -> TOKEN_EOF
| 1 -> TOKEN_QUESTION_MARK
| 2 -> TOKEN_SEMICOLON
| 3 -> TOKEN_COMMA
| 4 -> TOKEN_RIGHT_BRACKET
| 5 -> TOKEN_LEFT_BRACKET
| 6 -> TOKEN_RIGHT_PAREN
| 7 -> TOKEN_LEFT_PAREN
| 8 -> TOKEN_IDENTIFIER
| 11 -> TOKEN_end_of_input
| 9 -> 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__startinstr
| 1 -> NONTERM_instr
| 2 -> NONTERM_operands
| 3 -> NONTERM_operands
| 4 -> NONTERM_operands
| 5 -> NONTERM_operand
| 6 -> NONTERM_operand
| _ -> failwith "prodIdxToNonTerminal: bad production index"
let _fsyacc_endOfInputTag = 11
let _fsyacc_tagOfErrorTerminal = 9
// This function gets the name of a token as a string
let token_to_string (t:token) =
match t with
| EOF -> "EOF"
| QUESTION_MARK -> "QUESTION_MARK"
| SEMICOLON -> "SEMICOLON"
| COMMA -> "COMMA"
| RIGHT_BRACKET -> "RIGHT_BRACKET"
| LEFT_BRACKET -> "LEFT_BRACKET"
| RIGHT_PAREN -> "RIGHT_PAREN"
| LEFT_PAREN -> "LEFT_PAREN"
| IDENTIFIER _ -> "IDENTIFIER"
// This function gets the data carried by a token as an object
let _fsyacc_dataOfToken (t:token) =
match t with
| EOF -> (null : System.Object)
| QUESTION_MARK -> (null : System.Object)
| SEMICOLON -> (null : System.Object)
| COMMA -> (null : System.Object)
| RIGHT_BRACKET -> (null : System.Object)
| LEFT_BRACKET -> (null : System.Object)
| RIGHT_PAREN -> (null : System.Object)
| LEFT_PAREN -> (null : System.Object)
| IDENTIFIER _fsyacc_x -> Microsoft.FSharp.Core.Operators.box _fsyacc_x
let _fsyacc_gotos = [| 0us;65535us;1us;65535us;0us;1us;2us;65535us;3us;4us;7us;8us;2us;65535us;3us;6us;7us;6us;|]
let _fsyacc_sparseGotoTableRowOffsets = [|0us;1us;3us;6us;|]
let _fsyacc_stateToProdIdxsTableElements = [| 1us;0us;1us;0us;1us;1us;1us;1us;1us;1us;1us;1us;2us;3us;4us;1us;3us;1us;3us;1us;5us;1us;6us;|]
let _fsyacc_stateToProdIdxsTableRowOffsets = [|0us;2us;4us;6us;8us;10us;12us;15us;17us;19us;21us;|]
let _fsyacc_action_rows = 11
let _fsyacc_actionTableElements = [|1us;32768us;8us;2us;0us;49152us;1us;32768us;7us;3us;2us;16386us;1us;10us;8us;9us;1us;32768us;6us;5us;0us;16385us;1us;16388us;3us;7us;2us;16386us;1us;10us;8us;9us;0us;16387us;0us;16389us;0us;16390us;|]
let _fsyacc_actionTableRowOffsets = [|0us;2us;3us;5us;8us;10us;11us;13us;16us;17us;18us;|]
let _fsyacc_reductionSymbolCounts = [|1us;4us;0us;3us;1us;1us;1us;|]
let _fsyacc_productionToNonTerminalTable = [|0us;1us;2us;2us;2us;3us;3us;|]
let _fsyacc_immediateActions = [|65535us;49152us;65535us;65535us;65535us;16385us;65535us;65535us;16387us;16389us;16390us;|]
let _fsyacc_reductions = lazy [|
# 123 "Parser.fs"
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
let _1 = parseState.GetInput(1) :?> Instr in
Microsoft.FSharp.Core.Operators.box
(
(
raise (FSharp.Text.Parsing.Accept(Microsoft.FSharp.Core.Operators.box _1))
)
: 'gentype__startinstr));
# 132 "Parser.fs"
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
let _1 = parseState.GetInput(1) :?> string in
let _3 = parseState.GetInput(3) :?> 'gentype_operands in
Microsoft.FSharp.Core.Operators.box
(
(
# 29 "Parser.fsy"
{ Op = _1; Args = _3 }
)
# 29 "Parser.fsy"
: Instr));
# 144 "Parser.fs"
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
Microsoft.FSharp.Core.Operators.box
(
(
# 32 "Parser.fsy"
[]
)
# 32 "Parser.fsy"
: 'gentype_operands));
# 154 "Parser.fs"
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
let _1 = parseState.GetInput(1) :?> 'gentype_operand in
let _3 = parseState.GetInput(3) :?> 'gentype_operands in
Microsoft.FSharp.Core.Operators.box
(
(
# 33 "Parser.fsy"
_1 :: _3
)
# 33 "Parser.fsy"
: 'gentype_operands));
# 166 "Parser.fs"
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
let _1 = parseState.GetInput(1) :?> 'gentype_operand in
Microsoft.FSharp.Core.Operators.box
(
(
# 34 "Parser.fsy"
[ _1 ]
)
# 34 "Parser.fsy"
: 'gentype_operands));
# 177 "Parser.fs"
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
let _1 = parseState.GetInput(1) :?> string in
Microsoft.FSharp.Core.Operators.box
(
(
# 37 "Parser.fsy"
OperandTag _1
)
# 37 "Parser.fsy"
: 'gentype_operand));
# 188 "Parser.fs"
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
Microsoft.FSharp.Core.Operators.box
(
(
# 38 "Parser.fsy"
OperandHole
)
# 38 "Parser.fsy"
: 'gentype_operand));
|]
# 199 "Parser.fs"
let tables : FSharp.Text.Parsing.Tables<_> =
{ reductions = _fsyacc_reductions.Value;
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 = 12;
productionToNonTerminalTable = _fsyacc_productionToNonTerminalTable }
let engine lexer lexbuf startState = tables.Interpret(lexer, lexbuf, startState)
let instr lexer lexbuf : Instr =
engine lexer lexbuf 0 :?> _