From 5ba25d427099f29f184e1ff0d35dbc434fa264c9 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Sun, 7 Sep 2025 16:48:14 -0600 Subject: [PATCH] Start making generated parser --- ldedit/.gitignore => .gitignore | 0 ldtext/LDText.fs | 14 ++ ldtext/Library.fs | 5 + ldtext/Parser.fsy | 38 +++++ ldtext/ldtext.fsproj | 20 +++ reference data/simple_program.L5X | 238 ++++++++++++++++++++++++++++++ 6 files changed, 315 insertions(+) rename ldedit/.gitignore => .gitignore (100%) create mode 100644 ldtext/LDText.fs create mode 100644 ldtext/Library.fs create mode 100644 ldtext/Parser.fsy create mode 100644 ldtext/ldtext.fsproj create mode 100644 reference data/simple_program.L5X diff --git a/ldedit/.gitignore b/.gitignore similarity index 100% rename from ldedit/.gitignore rename to .gitignore diff --git a/ldtext/LDText.fs b/ldtext/LDText.fs new file mode 100644 index 0000000..08b29fd --- /dev/null +++ b/ldtext/LDText.fs @@ -0,0 +1,14 @@ +module LDText + +module Ast = + type Rung = Step list + + and Instr = { Op: string; Args: Operand list } + + and Step = + | StepInstr of Instr + | StepBranch of Step list + + and Operand = + | OperandHole + | OperandTag of string diff --git a/ldtext/Library.fs b/ldtext/Library.fs new file mode 100644 index 0000000..470ac73 --- /dev/null +++ b/ldtext/Library.fs @@ -0,0 +1,5 @@ +namespace ldtext + +module Say = + let hello name = + printfn "Hello %s" name diff --git a/ldtext/Parser.fsy b/ldtext/Parser.fsy new file mode 100644 index 0000000..bad1531 --- /dev/null +++ b/ldtext/Parser.fsy @@ -0,0 +1,38 @@ +%{ +open LDText.Ast +// helper functions +%} + +// start token +%start start + +// 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 + +// return type of parser, marked by start token +%type 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 } +%% diff --git a/ldtext/ldtext.fsproj b/ldtext/ldtext.fsproj new file mode 100644 index 0000000..9bd8f1c --- /dev/null +++ b/ldtext/ldtext.fsproj @@ -0,0 +1,20 @@ + + + + net9.0 + true + + + + + + --module Parser + + + + + + + + + diff --git a/reference data/simple_program.L5X b/reference data/simple_program.L5X new file mode 100644 index 0000000..cdcbd53 --- /dev/null +++ b/reference data/simple_program.L5X @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + Embedded + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file