Created
February 4, 2019 14:21
-
-
Save gabriel-fallen/d7b266d3cd2426548b3127e26f1dabbf to your computer and use it in GitHub Desktop.
YaccConstructor test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Test | |
| open AbstractAnalysis.Common | |
| open Yard.Generators.Common.DataStructures | |
| open Yard.Generators.GLL | |
| open Yard.Generators.GLL.AbstractParser | |
| open GrammarCombinator.Combinators | |
| module Test = | |
| let private psgll def : ParserCommon.ParserSourceGLL = | |
| let gll = new GLL() in | |
| gll.Generate(def, false) :?> ParserCommon.ParserSourceGLL | |
| // s : A s B s | {None} | |
| let testCFPQ () = | |
| <@ | |
| let rec s() = tok "A" + s() + tok "B" + s() <|> Eps | |
| in s() | |
| @> | |
| let testCFPQ2 () = | |
| <@ | |
| let rec s() = tok "A" + s() + tok "B" <|> Eps in | |
| let p() = tok "In" + s() + tok "Out" | |
| in p() | |
| @> | |
| let private triples = [| | |
| (0, 1, "In"); | |
| (1, 2, "A"); | |
| (2, 1, "B"); | |
| (1, 3, "Out") | |
| |] | |
| let private pairs = [| | |
| (0, 1); | |
| (0, 2); | |
| (0, 3); | |
| (1, 4); | |
| (4, 1); | |
| (2, 5); | |
| (2, 6); | |
| (3, 6); | |
| (5, 7); | |
| (7, 5) | |
| |] | |
| let private allVs0 = triples |> Array.collect (fun (f,t,l) -> [|f * 1<positionInInput>; t * 1<positionInInput>|]) |> Set.ofArray |> Array.ofSeq | |
| let private allVs = pairs |> Array.collect (fun (f,t) -> [|f * 1<positionInInput>; t * 1<positionInInput>|]) |> Set.ofArray |> Array.ofSeq | |
| let private direction f t = if f < t then "A" else "B" | |
| let private directionToToken = function | |
| | "A" -> 1<token> | |
| | _ -> -1<token> | |
| let private edg f t = | |
| [| new ParserEdge<_>(f, t, direction f t) |] | |
| let private edg3 f t l = | |
| [| new ParserEdge<_>(f, t, l) |] | |
| let testGraph = | |
| let g = new SimpleInputGraph<string>(allVs, directionToToken) | |
| [|for (f,t) in pairs -> edg f t |] | |
| |> Array.concat | |
| |> g.AddVerticesAndEdgeRange | |
| |> ignore | |
| g | |
| let testGraph0 = | |
| let g = new SimpleInputGraph<string>(allVs0, directionToToken) | |
| [|for (f,t, l) in triples -> edg3 f t l |] | |
| |> Array.concat | |
| |> g.AddVerticesAndEdgeRange | |
| |> ignore | |
| g | |
| let sppfTest def graph nonTermName maxLength = | |
| let ps = psgll def | |
| // let preparedGraph = initGraph inputGraph id ps | |
| let gss, sppf, _ = parse ps graph true | |
| let nt = sppf.GetNonTermByName nonTermName ps | |
| let pathset = sppf.Iterate nt ps maxLength | |
| // maxLength = Seq.length pathset | |
| pathset | |
| let private testDef = testCFPQ () |> GrammarCombinator.GrammarGenerator.generate "unique" | |
| let private testDef2 = testCFPQ2 () |> GrammarCombinator.GrammarGenerator.generate "unique2" | |
| let zeroTest = sppfTest testDef2 testGraph0 "p$4" 10 | |
| let firstTest = sppfTest testDef testGraph "s$1" 10 | |
| module Main = | |
| open Test | |
| let main = printfn "%A" firstTest | |
| let _ = printfn "%A" zeroTest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment