%{ 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: | { [] } | instr steps { StepInstr $1 :: $2 } | branch steps { StepBranch $1 :: $2 } branch: | LEFT_BRACKET branch_arms RIGHT_BRACKET { Branch $2 } branch_arms: | { [] } | steps COMMA branch_arms { BranchArm $1 :: $3} | steps { [ BranchArm $1 ] } instr: | IDENTIFIER LEFT_PAREN operands RIGHT_PAREN { { Op = $1; Args = $3 } } operands: | { [] } | operand COMMA operands { $1 :: $3 } | operand { [ $1 ] } operand: | IDENTIFIER { OperandTag $1 } | QUESTION_MARK { OperandHole } %%