Parse single instruction in neutral text

This commit is contained in:
2025-09-07 21:20:32 -06:00
parent 5ba25d4270
commit 925e486e65
15 changed files with 482 additions and 18 deletions

View File

@@ -1,10 +1,10 @@
%{
open LDText.Ast
// helper functions
open FSharp.Text.Lexing
%}
// start token
%start start
%start instr
// tokens, used by lexer
%token <string> IDENTIFIER
@@ -18,19 +18,20 @@ open LDText.Ast
%token EOF
// return type of parser, marked by start token
%type <Rung option> rung
%type <Instr> instr
%%
start:
| instr EOF { $1 }
//rung:
// | instr EOF { $1 }
instr:
| IDENTIFIER LEFT_PAREN operands RIGHT_PAREN { StepInstr { Op = $1; Args = [ $3 ] } }
| IDENTIFIER LEFT_PAREN operands RIGHT_PAREN { { Op = $1; Args = $3 } }
operands:
| { }
| operand operands { $1; $2 }
| { [] }
| operand COMMA operands { $1 :: $3 }
| operand { [ $1 ] }
operand:
| IDENTIFIER { OperandTag $1 }