Start making generated parser

This commit is contained in:
2025-09-07 16:48:14 -06:00
parent 2154730334
commit 5ba25d4270
6 changed files with 315 additions and 0 deletions

38
ldtext/Parser.fsy Normal file
View File

@@ -0,0 +1,38 @@
%{
open LDText.Ast
// helper functions
%}
// start token
%start start
// 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
// return type of parser, marked by start token
%type <Rung option> rung
%%
start:
| instr EOF { $1 }
instr:
| IDENTIFIER LEFT_PAREN operands RIGHT_PAREN { StepInstr { Op = $1; Args = [ $3 ] } }
operands:
| { }
| operand operands { $1; $2 }
operand:
| IDENTIFIER { OperandTag $1 }
| QUESTION_MARK { OperandHole }
%%