Start making generated parser
This commit is contained in:
14
ldtext/LDText.fs
Normal file
14
ldtext/LDText.fs
Normal file
@@ -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
|
5
ldtext/Library.fs
Normal file
5
ldtext/Library.fs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace ldtext
|
||||
|
||||
module Say =
|
||||
let hello name =
|
||||
printfn "Hello %s" name
|
38
ldtext/Parser.fsy
Normal file
38
ldtext/Parser.fsy
Normal 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 }
|
||||
%%
|
20
ldtext/ldtext.fsproj
Normal file
20
ldtext/ldtext.fsproj
Normal file
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup><Compile Include="LDText.fs" />
|
||||
<Compile Include="LDText.fs" />
|
||||
<FsYacc Include="Parser.fsy">
|
||||
<OtherFlags>--module Parser</OtherFlags>
|
||||
</FsYacc>
|
||||
<Compile Include="Library.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FsLexYacc" Version="11.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user