363 lines
14 KiB
Forth
363 lines
14 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__startrung
|
|
| NONTERM_rung
|
|
| NONTERM_steps
|
|
| NONTERM_steps_reversed
|
|
| NONTERM_branch
|
|
| NONTERM_branch_arms
|
|
| NONTERM_branch_arms_reversed
|
|
| NONTERM_instr
|
|
| NONTERM_operands
|
|
| NONTERM_operands_reversed
|
|
| 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__startrung
|
|
| 1 -> NONTERM_rung
|
|
| 2 -> NONTERM_steps
|
|
| 3 -> NONTERM_steps_reversed
|
|
| 4 -> NONTERM_steps_reversed
|
|
| 5 -> NONTERM_steps_reversed
|
|
| 6 -> NONTERM_branch
|
|
| 7 -> NONTERM_branch_arms
|
|
| 8 -> NONTERM_branch_arms_reversed
|
|
| 9 -> NONTERM_branch_arms_reversed
|
|
| 10 -> NONTERM_branch_arms_reversed
|
|
| 11 -> NONTERM_instr
|
|
| 12 -> NONTERM_operands
|
|
| 13 -> NONTERM_operands_reversed
|
|
| 14 -> NONTERM_operands_reversed
|
|
| 15 -> NONTERM_operands_reversed
|
|
| 16 -> NONTERM_operand
|
|
| 17 -> 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;3us;65535us;0us;2us;8us;14us;12us;13us;3us;65535us;0us;5us;8us;5us;12us;5us;1us;65535us;5us;7us;1us;65535us;8us;9us;1us;65535us;8us;11us;1us;65535us;5us;6us;1us;65535us;16us;17us;1us;65535us;16us;19us;2us;65535us;16us;22us;20us;21us;|]
|
|
let _fsyacc_sparseGotoTableRowOffsets = [|0us;1us;3us;7us;11us;13us;15us;17us;19us;21us;23us;|]
|
|
let _fsyacc_stateToProdIdxsTableElements = [| 1us;0us;1us;0us;1us;1us;1us;1us;1us;1us;3us;2us;4us;5us;1us;4us;1us;5us;1us;6us;1us;6us;1us;6us;2us;7us;9us;1us;9us;1us;9us;1us;10us;1us;11us;1us;11us;1us;11us;1us;11us;2us;12us;14us;1us;14us;1us;14us;1us;15us;1us;16us;1us;17us;|]
|
|
let _fsyacc_stateToProdIdxsTableRowOffsets = [|0us;2us;4us;6us;8us;10us;14us;16us;18us;20us;22us;24us;27us;29us;31us;33us;35us;37us;39us;41us;44us;46us;48us;50us;52us;|]
|
|
let _fsyacc_action_rows = 25
|
|
let _fsyacc_actionTableElements = [|0us;16387us;0us;49152us;1us;32768us;2us;3us;1us;32768us;0us;4us;0us;16385us;2us;16386us;5us;8us;8us;15us;0us;16388us;0us;16389us;0us;16387us;1us;32768us;4us;10us;0us;16390us;1us;16391us;3us;12us;0us;16387us;0us;16393us;0us;16394us;1us;32768us;7us;16us;2us;16397us;1us;24us;8us;23us;1us;32768us;6us;18us;0us;16395us;1us;16396us;3us;20us;2us;32768us;1us;24us;8us;23us;0us;16398us;0us;16399us;0us;16400us;0us;16401us;|]
|
|
let _fsyacc_actionTableRowOffsets = [|0us;1us;2us;4us;6us;7us;10us;11us;12us;13us;15us;16us;18us;19us;20us;21us;23us;26us;28us;29us;31us;34us;35us;36us;37us;|]
|
|
let _fsyacc_reductionSymbolCounts = [|1us;3us;1us;0us;2us;2us;3us;1us;0us;3us;1us;4us;1us;0us;3us;1us;1us;1us;|]
|
|
let _fsyacc_productionToNonTerminalTable = [|0us;1us;2us;3us;3us;3us;4us;5us;6us;6us;6us;7us;8us;9us;9us;9us;10us;10us;|]
|
|
let _fsyacc_immediateActions = [|65535us;49152us;65535us;65535us;16385us;65535us;16388us;16389us;65535us;65535us;16390us;65535us;65535us;16393us;16394us;65535us;65535us;65535us;16395us;65535us;65535us;16398us;16399us;16400us;16401us;|]
|
|
let _fsyacc_reductions = lazy [|
|
|
# 141 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> Rung in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
raise (FSharp.Text.Parsing.Accept(Microsoft.FSharp.Core.Operators.box _1))
|
|
)
|
|
: 'gentype__startrung));
|
|
# 150 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_steps in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 26 "Parser.fsy"
|
|
Rung _1
|
|
)
|
|
# 26 "Parser.fsy"
|
|
: Rung));
|
|
# 161 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_steps_reversed in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 29 "Parser.fsy"
|
|
List.rev _1
|
|
)
|
|
# 29 "Parser.fsy"
|
|
: 'gentype_steps));
|
|
# 172 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 32 "Parser.fsy"
|
|
[]
|
|
)
|
|
# 32 "Parser.fsy"
|
|
: 'gentype_steps_reversed));
|
|
# 182 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_steps_reversed in
|
|
let _2 = parseState.GetInput(2) :?> 'gentype_instr in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 33 "Parser.fsy"
|
|
StepInstr _2 :: _1
|
|
)
|
|
# 33 "Parser.fsy"
|
|
: 'gentype_steps_reversed));
|
|
# 194 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_steps_reversed in
|
|
let _2 = parseState.GetInput(2) :?> 'gentype_branch in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 34 "Parser.fsy"
|
|
StepBranch _2 :: _1
|
|
)
|
|
# 34 "Parser.fsy"
|
|
: 'gentype_steps_reversed));
|
|
# 206 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _2 = parseState.GetInput(2) :?> 'gentype_branch_arms in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 37 "Parser.fsy"
|
|
Branch _2
|
|
)
|
|
# 37 "Parser.fsy"
|
|
: 'gentype_branch));
|
|
# 217 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_branch_arms_reversed in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 40 "Parser.fsy"
|
|
List.rev _1
|
|
)
|
|
# 40 "Parser.fsy"
|
|
: 'gentype_branch_arms));
|
|
# 228 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 43 "Parser.fsy"
|
|
[]
|
|
)
|
|
# 43 "Parser.fsy"
|
|
: 'gentype_branch_arms_reversed));
|
|
# 238 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_branch_arms_reversed in
|
|
let _3 = parseState.GetInput(3) :?> 'gentype_steps in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 44 "Parser.fsy"
|
|
BranchArm _3 :: _1
|
|
)
|
|
# 44 "Parser.fsy"
|
|
: 'gentype_branch_arms_reversed));
|
|
# 250 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_steps in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 45 "Parser.fsy"
|
|
[ BranchArm _1 ]
|
|
)
|
|
# 45 "Parser.fsy"
|
|
: 'gentype_branch_arms_reversed));
|
|
# 261 "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
|
|
(
|
|
(
|
|
# 48 "Parser.fsy"
|
|
{ Op = _1; Args = _3 }
|
|
)
|
|
# 48 "Parser.fsy"
|
|
: 'gentype_instr));
|
|
# 273 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_operands_reversed in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 51 "Parser.fsy"
|
|
List.rev _1
|
|
)
|
|
# 51 "Parser.fsy"
|
|
: 'gentype_operands));
|
|
# 284 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 54 "Parser.fsy"
|
|
[]
|
|
)
|
|
# 54 "Parser.fsy"
|
|
: 'gentype_operands_reversed));
|
|
# 294 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_operands_reversed in
|
|
let _3 = parseState.GetInput(3) :?> 'gentype_operand in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 55 "Parser.fsy"
|
|
_3 :: _1
|
|
)
|
|
# 55 "Parser.fsy"
|
|
: 'gentype_operands_reversed));
|
|
# 306 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_operand in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 56 "Parser.fsy"
|
|
[ _1 ]
|
|
)
|
|
# 56 "Parser.fsy"
|
|
: 'gentype_operands_reversed));
|
|
# 317 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> string in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 59 "Parser.fsy"
|
|
OperandTag _1
|
|
)
|
|
# 59 "Parser.fsy"
|
|
: 'gentype_operand));
|
|
# 328 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 60 "Parser.fsy"
|
|
OperandHole
|
|
)
|
|
# 60 "Parser.fsy"
|
|
: 'gentype_operand));
|
|
|]
|
|
# 339 "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 rung lexer lexbuf : Rung =
|
|
engine lexer lexbuf 0 :?> _
|