Parse branches

This commit is contained in:
2025-09-07 22:15:25 -06:00
parent 43107e7435
commit 46f2bbcc9b
5 changed files with 136 additions and 54 deletions

View File

@@ -18,16 +18,25 @@ open FSharp.Text.Lexing
%start rung
// return type of parser, marked by start token
%type <Instr list> rung
%type <Rung> rung
%%
rung:
| steps SEMICOLON EOF { $1 }
| steps SEMICOLON EOF { Rung $1 }
steps:
| { [] }
| instr steps { $1 :: $2 }
| 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 } }