Math.NET Numerics
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

52 lines
1.7 KiB

%{
(* (c) Microsoft Corporation 2005-2008. *)
open Fsyaccast
#nowarn "62" // This construct is for compatibility with OCaml
%}
%type <Fsyaccast.ParserSpec> spec
%token <string> IDENT
%token <Fsyaccast.Code> HEADER CODE
%token BAR PERCENT_PERCENT START LEFT RIGHT NONASSOC LESS GREATER COLON PREC SEMI EOF ERROR
%token <string> TYPE
%token <string option> TOKEN
%start spec
%left BAR
%%
spec:
headeropt decls PERCENT_PERCENT rules
{ List.fold_right (fun f x -> f x) $2 { Header=$1;Tokens=[];Types=[];Associativities=[];StartSymbols=[];Rules=$4 } }
headeropt:
| HEADER
{ $1 }
|
{ "", (parseState.ResultRange |> fst)}
decls:
{ [] }
| decl decls { $1 :: $2 }
decl:
TOKEN idents { (fun x -> {x with Tokens = x.Tokens @ (List.map (fun x -> (x,$1)) $2)}) }
| TYPE idents { (fun x -> {x with Types = x.Types @ (List.map (fun x -> (x,$1)) $2)} ) }
| START idents { (fun x -> {x with StartSymbols = x.StartSymbols @ $2} ) }
| LEFT idents { (fun x -> {x with Associativities = x.Associativities @ [(List.map (fun x -> (x,LeftAssoc)) $2)]} ) }
| RIGHT idents { (fun x -> {x with Associativities = x.Associativities @ [(List.map (fun x -> (x,RightAssoc)) $2)]} ) }
| NONASSOC idents { (fun x -> {x with Associativities = x.Associativities @ [(List.map (fun x -> (x,NonAssoc)) $2)]} ) }
idents: IDENT idents { $1 :: $2 } | { [] }
rules: rule rules { $1 :: $2 } | rule { [$1] }
rule: IDENT COLON optbar clauses optsemi { ($1,$4) }
optbar: { } | BAR { }
optsemi: { } | SEMI { }
clauses: clause BAR clauses {$1 :: $3 } | clause { [$1] }
clause: syms optprec CODE { Rule($1,$2,Some $3) }
syms: IDENT syms { $1 :: $2 } | ERROR syms { "error" :: $2 } | { [] }
optprec: { None } | PREC IDENT { Some $2 }