324 lines
12 KiB
Forth
324 lines
12 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_branch
|
|
| NONTERM_branch_arms
|
|
| 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__startrung
|
|
| 1 -> NONTERM_rung
|
|
| 2 -> NONTERM_steps
|
|
| 3 -> NONTERM_steps
|
|
| 4 -> NONTERM_steps
|
|
| 5 -> NONTERM_branch
|
|
| 6 -> NONTERM_branch_arms
|
|
| 7 -> NONTERM_branch_arms
|
|
| 8 -> NONTERM_branch_arms
|
|
| 9 -> NONTERM_instr
|
|
| 10 -> NONTERM_operands
|
|
| 11 -> NONTERM_operands
|
|
| 12 -> NONTERM_operands
|
|
| 13 -> NONTERM_operand
|
|
| 14 -> 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;5us;65535us;0us;2us;5us;6us;7us;8us;9us;12us;13us;12us;5us;65535us;0us;7us;5us;7us;7us;7us;9us;7us;13us;7us;2us;65535us;9us;10us;13us;14us;5us;65535us;0us;5us;5us;5us;7us;5us;9us;5us;13us;5us;2us;65535us;16us;17us;20us;21us;2us;65535us;16us;19us;20us;19us;|]
|
|
let _fsyacc_sparseGotoTableRowOffsets = [|0us;1us;3us;9us;15us;18us;24us;27us;|]
|
|
let _fsyacc_stateToProdIdxsTableElements = [| 1us;0us;1us;0us;1us;1us;1us;1us;1us;1us;1us;3us;1us;3us;1us;4us;1us;4us;1us;5us;1us;5us;1us;5us;2us;7us;8us;1us;7us;1us;7us;1us;9us;1us;9us;1us;9us;1us;9us;2us;11us;12us;1us;11us;1us;11us;1us;13us;1us;14us;|]
|
|
let _fsyacc_stateToProdIdxsTableRowOffsets = [|0us;2us;4us;6us;8us;10us;12us;14us;16us;18us;20us;22us;24us;27us;29us;31us;33us;35us;37us;39us;42us;44us;46us;48us;|]
|
|
let _fsyacc_action_rows = 24
|
|
let _fsyacc_actionTableElements = [|2us;16386us;5us;9us;8us;15us;0us;49152us;1us;32768us;2us;3us;1us;32768us;0us;4us;0us;16385us;2us;16386us;5us;9us;8us;15us;0us;16387us;2us;16386us;5us;9us;8us;15us;0us;16388us;2us;16386us;5us;9us;8us;15us;1us;32768us;4us;11us;0us;16389us;1us;16392us;3us;13us;2us;16386us;5us;9us;8us;15us;0us;16391us;1us;32768us;7us;16us;2us;16394us;1us;23us;8us;22us;1us;32768us;6us;18us;0us;16393us;1us;16396us;3us;20us;2us;16394us;1us;23us;8us;22us;0us;16395us;0us;16397us;0us;16398us;|]
|
|
let _fsyacc_actionTableRowOffsets = [|0us;3us;4us;6us;8us;9us;12us;13us;16us;17us;20us;22us;23us;25us;28us;29us;31us;34us;36us;37us;39us;42us;43us;44us;|]
|
|
let _fsyacc_reductionSymbolCounts = [|1us;3us;0us;2us;2us;3us;0us;3us;1us;4us;0us;3us;1us;1us;1us;|]
|
|
let _fsyacc_productionToNonTerminalTable = [|0us;1us;2us;2us;2us;3us;4us;4us;4us;5us;6us;6us;6us;7us;7us;|]
|
|
let _fsyacc_immediateActions = [|65535us;49152us;65535us;65535us;16385us;65535us;16387us;65535us;16388us;65535us;65535us;16389us;65535us;65535us;16391us;65535us;65535us;65535us;16393us;65535us;65535us;16395us;16397us;16398us;|]
|
|
let _fsyacc_reductions = lazy [|
|
|
# 135 "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));
|
|
# 144 "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));
|
|
# 155 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 29 "Parser.fsy"
|
|
[]
|
|
)
|
|
# 29 "Parser.fsy"
|
|
: 'gentype_steps));
|
|
# 165 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_instr in
|
|
let _2 = parseState.GetInput(2) :?> 'gentype_steps in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 30 "Parser.fsy"
|
|
StepInstr _1 :: _2
|
|
)
|
|
# 30 "Parser.fsy"
|
|
: 'gentype_steps));
|
|
# 177 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_branch in
|
|
let _2 = parseState.GetInput(2) :?> 'gentype_steps in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 31 "Parser.fsy"
|
|
StepBranch _1 :: _2
|
|
)
|
|
# 31 "Parser.fsy"
|
|
: 'gentype_steps));
|
|
# 189 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _2 = parseState.GetInput(2) :?> 'gentype_branch_arms in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 34 "Parser.fsy"
|
|
Branch _2
|
|
)
|
|
# 34 "Parser.fsy"
|
|
: 'gentype_branch));
|
|
# 200 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 37 "Parser.fsy"
|
|
[]
|
|
)
|
|
# 37 "Parser.fsy"
|
|
: 'gentype_branch_arms));
|
|
# 210 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_steps in
|
|
let _3 = parseState.GetInput(3) :?> 'gentype_branch_arms in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 38 "Parser.fsy"
|
|
BranchArm _1 :: _3
|
|
)
|
|
# 38 "Parser.fsy"
|
|
: 'gentype_branch_arms));
|
|
# 222 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_steps in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 39 "Parser.fsy"
|
|
[ BranchArm _1 ]
|
|
)
|
|
# 39 "Parser.fsy"
|
|
: 'gentype_branch_arms));
|
|
# 233 "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
|
|
(
|
|
(
|
|
# 42 "Parser.fsy"
|
|
{ Op = _1; Args = _3 }
|
|
)
|
|
# 42 "Parser.fsy"
|
|
: 'gentype_instr));
|
|
# 245 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 45 "Parser.fsy"
|
|
[]
|
|
)
|
|
# 45 "Parser.fsy"
|
|
: 'gentype_operands));
|
|
# 255 "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
|
|
(
|
|
(
|
|
# 46 "Parser.fsy"
|
|
_1 :: _3
|
|
)
|
|
# 46 "Parser.fsy"
|
|
: 'gentype_operands));
|
|
# 267 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> 'gentype_operand in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 47 "Parser.fsy"
|
|
[ _1 ]
|
|
)
|
|
# 47 "Parser.fsy"
|
|
: 'gentype_operands));
|
|
# 278 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
let _1 = parseState.GetInput(1) :?> string in
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 50 "Parser.fsy"
|
|
OperandTag _1
|
|
)
|
|
# 50 "Parser.fsy"
|
|
: 'gentype_operand));
|
|
# 289 "Parser.fs"
|
|
(fun (parseState : FSharp.Text.Parsing.IParseState) ->
|
|
Microsoft.FSharp.Core.Operators.box
|
|
(
|
|
(
|
|
# 51 "Parser.fsy"
|
|
OperandHole
|
|
)
|
|
# 51 "Parser.fsy"
|
|
: 'gentype_operand));
|
|
|]
|
|
# 300 "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 :?> _
|