Start making generated parser
This commit is contained in:
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 }
|
||||
%%
|
Reference in New Issue
Block a user