Exemplo n.º 1
0
        public static Grammar LoadGrammar(string pathGrammarFile, bool verbose = false, params Type[] types)
        {
            var assemblies = new Assembly[types.Length];

            for (int i = 0; i < types.Length; ++i)
            {
                assemblies[i] = types[i].GetTypeInfo().Assembly;
            }
            var compilationResult = DSLCompiler.Compile(new CompilerOptions()
            {
                InputGrammarText = File.ReadAllText(pathGrammarFile),
                References       = CompilerReference.FromAssemblyFiles(assemblies)
            });

            if (verbose)
            {
                if (compilationResult.HasErrors)
                {
                    Console.WriteLine("Compilation HasErrors! Trace: ");
                    compilationResult.TraceDiagnostics();
                    Console.WriteLine("------------------------------------------");
                }
                else
                {
                    Console.WriteLine("No Errors in Compilation. Trace: ");
                    compilationResult.TraceDiagnostics();
                    Console.WriteLine("------------------------------------------");
                }
            }

            return(compilationResult.HasErrors ? null : compilationResult.Value);
        }
Exemplo n.º 2
0
        public static void Setup()
        {
            _grammar = LoadGrammar("TreeLang.grammar",
                                   CompilerReference.FromAssemblyFiles(
                                       typeof(Microsoft.ProgramSynthesis.Utils.Record).GetTypeInfo().Assembly,
                                       typeof(Semantics).GetTypeInfo().Assembly,
                                       typeof(SyntaxNode).GetTypeInfo().Assembly));
            if (_grammar == null)
            {
                Log.Error("Failed to compile TreeLang.grammar.");
                return;
            }

            InputSymbol = _grammar.InputSymbol;

            _scorer = new RankingScore(_grammar);
            _engine = new SynthesisEngine(_grammar, new SynthesisEngine.Config
            {
                Strategies = new ISynthesisStrategy[]
                {
                    new PremStrategy(_grammar),
                },
                UseThreads = false
            });

            Log.Debug("Transformer: synthesis engine is setup.");
        }
Exemplo n.º 3
0
 private static Result <Grammar> CompileGrammar()
 {
     return(DSLCompiler.Compile(new CompilerOptions
     {
         InputGrammarText = File.ReadAllText(GrammarPath),
         References = CompilerReference.FromAssemblyFiles(typeof(Semantics).GetTypeInfo().Assembly)
     }));
 }
Exemplo n.º 4
0
        private LanguageGrammar()
        {
            var options = new CompilerOptions
            {
                InputGrammarText = GrammarContent,
                References       = CompilerReference.FromAssemblyFiles(
                    typeof(Semantics).GetTypeInfo().Assembly,
                    typeof(Microsoft.ProgramSynthesis.Wrangling.Tree.Node).GetTypeInfo().Assembly)
            };

            Result <Grammar> compile = DSLCompiler.Compile(options);

            Grammar = compile.Value;
        }
Exemplo n.º 5
0
        static Grammar getGrammar()
        {
            var g = DSLCompiler.Compile(new CompilerOptions
            {
                InputGrammarText = File.ReadAllText("SExp.grammar"),
                References       = CompilerReference.FromAssemblyFiles(
                    typeof(SExpProgram).GetTypeInfo().Assembly,
                    typeof(Semantics.SExp).GetTypeInfo().Assembly,
                    typeof(Semantics.Semantics).GetTypeInfo().Assembly,
                    typeof(Learning.RankingScore).GetTypeInfo().Assembly)
            });

            return(g.Value);
        }
Exemplo n.º 6
0
        private static void LoadAndTestTextExtraction()
        {
            var grammar = LoadGrammar("ProseSample.TextExtraction.grammar",
                                      CompilerReference.FromAssemblyFiles(typeof(Substring).GetTypeInfo().Assembly,
                                                                          typeof(TextExtraction.Semantics).GetTypeInfo().Assembly,
                                                                          typeof(Substrings.Language).GetTypeInfo().Assembly));

            if (grammar == null)
            {
                WriteColored(ConsoleColor.Magenta,
                             "Compilation of ProseSample.TextExtraction.grammar failed: skipping tests");
                return;
            }

            TestExtractionBenchmark(grammar, "areas");
            TestExtractionBenchmark(grammar, "popl13-erc");
        }
Exemplo n.º 7
0
        public TransformationsController()
        {
            const string grammarFileName = @"Prose/Transformations.grammar";

            var reader  = new StreamReader(PathToFiles + grammarFileName);
            var grammar = reader.ReadToEnd();

            _grammar = DSLCompiler.Compile(
                new CompilerOptions()
            {
                InputGrammarText = grammar,
                References       = CompilerReference.FromAssemblyFiles(
                    typeof(List <int>).GetTypeInfo().Assembly,
                    typeof(Semantics).GetTypeInfo().Assembly,
                    typeof(Node).GetTypeInfo().Assembly)
            }
                );
        }
Exemplo n.º 8
0
        private static void LoadAndTestSubstrings()
        {
            var grammar = LoadGrammar("ProseSample.Substrings.grammar",
                                      CompilerReference.FromAssemblyFiles(typeof(StringRegion).GetTypeInfo().Assembly,
                                                                          typeof(Substrings.Semantics).GetTypeInfo().Assembly,
                                                                          typeof(Record).GetTypeInfo().Assembly));

            if (grammar == null)
            {
                return;
            }

            StringRegion prose = new StringRegion("Microsoft Program Synthesis using Examples SDK", Token.Tokens);
            StringRegion sdk   = prose.Slice(prose.End - 3, prose.End);
            Spec         spec  = ShouldConvert.Given(grammar).To(prose, sdk);

            Learn(grammar, spec, new Substrings.RankingScore(grammar), new Substrings.WitnessFunctions(grammar));

            TestFlashFillBenchmark(grammar, "emails");
        }