Files
control-see/ldtext/Parser.fsy
2025-09-07 22:15:25 -06:00

53 lines
899 B
Plaintext

%{
open LDText.Ast
open FSharp.Text.Lexing
%}
// tokens, used by lexer
%token <string> 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
%%
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 }
%%