Files
control-see/ldtext/Parser.fsy

44 lines
677 B
Plaintext

%{
open LDText.Ast
open FSharp.Text.Lexing
%}
// 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
// start token
%start rung
// return type of parser, marked by start token
%type <Instr list> rung
%%
rung:
| steps SEMICOLON EOF { $1 }
steps:
| { [] }
| instr steps { $1 :: $2 }
instr:
| IDENTIFIER LEFT_PAREN operands RIGHT_PAREN { { Op = $1; Args = $3 } }
operands:
| { [] }
| operand COMMA operands { $1 :: $3 }
| operand { [ $1 ] }
operand:
| IDENTIFIER { OperandTag $1 }
| QUESTION_MARK { OperandHole }
%%