%{ open LDText.Ast open FSharp.Text.Lexing %} // tokens, used by lexer %token IDENTIFIER %token LEFT_PAREN %token RIGHT_PAREN %token LEFT_BRACKET %token RIGHT_BRACKET %token COMMA %token SEMICOLON %token QUESTION_MARK %token EOF // start token %start rung // return type of parser, marked by start token %type rung %% rung: | steps SEMICOLON EOF { Rung $1 } steps: | steps_reversed { List.rev $1 } steps_reversed: | { [] } | steps_reversed instr { StepInstr $2 :: $1 } | steps_reversed branch { StepBranch $2 :: $1 } branch: | LEFT_BRACKET branch_arms RIGHT_BRACKET { Branch $2 } branch_arms: | branch_arms_reversed { List.rev $1 } branch_arms_reversed: | { [] } | branch_arms_reversed COMMA steps { BranchArm $3 :: $1} | steps { [ BranchArm $1 ] } instr: | IDENTIFIER LEFT_PAREN operands RIGHT_PAREN { { Op = $1; Args = $3 } } operands: | operands_reversed { List.rev $1 } operands_reversed: | { [] } | operands_reversed COMMA operand { $3 :: $1 } | operand { [ $1 ] } operand: | IDENTIFIER { OperandTag $1 } | QUESTION_MARK { OperandHole } %%