public static Grammar LoadGrammar(string grammarFile, params string[] prerequisiteGrammars) { foreach (string prerequisite in prerequisiteGrammars) { var options = new CompilerOptions { InputGrammar = prerequisite, Output = Path.GetFileNameWithoutExtension(prerequisite) + ".Language.dll", Verbosity = Verbosity.Normal }; var buildResult = DSLCompiler.Compile(options); if (!buildResult.HasErrors) { continue; } WriteColored(ConsoleColor.Magenta, buildResult.TraceDiagnostics); return(null); } var compilationResult = DSLCompiler.ParseGrammarFromFile(grammarFile); if (compilationResult.HasErrors) { WriteColored(ConsoleColor.Magenta, compilationResult.TraceDiagnostics); return(null); } if (compilationResult.Diagnostics.Count > 0) { WriteColored(ConsoleColor.Yellow, compilationResult.TraceDiagnostics); } return(compilationResult.Value); }
public Refazer4Python(string pathToGrammar = @"..\..\..\Tutor\synthesis\", string pathToDslLib = @"..\..\..\Tutor\bin\debug") { _pathToGrammar = pathToGrammar; _pathToDslLib = pathToDslLib; Grammar = DSLCompiler.ParseGrammarFromFile(pathToGrammar + @"Transformation.grammar", libraryPaths: new[] { pathToDslLib }); }
public static void Main(string[] args) { var parseResult = DSLCompiler.ParseGrammarFromFile("sorta.grammar"); foreach (var d in parseResult.Diagnostics) { System.Console.WriteLine(d); } if (parseResult.Value == null) { Console.WriteLine("Failed to load grammar (see errors above)"); return; } //--------------------------------------------------------------------------------- var grammar = parseResult.Value; Console.WriteLine("sucessfuly loaded: " + grammar.Name + "\n"); //--------------------------------------------------------------------------------- { ProgramNode p = ProgramNode.Parse("Length(x)", grammar, ASTSerializationFormat.HumanReadable); var inp = new Tuple <string, string>("aaa", "aa"); State input = State.Create(grammar.InputSymbol, inp); Console.WriteLine(p.Invoke(input)); } { /* * ProgramNode p = ProgramNode.Parse("FirstIndexOf(x, 'a')", grammar, ASTSerializationFormat.HumanReadable); * var inp = new Tuple<string, string>("aaa", "aa"); * State input = State.Create(grammar.InputSymbol, inp); * Console.WriteLine(p.Invoke(input)); */ } //--------------------------------------------------------------------------------- var g = grammar; var l = new sorta.Learning.Learners(g); // simple length comparisons Print(Learn(g, l, ex("aab", "bb", Order.Greater))); Print(Learn(g, l, ex("aab", "bb", Order.Less))); Print(Learn(g, l, ex("bb", "aab", Order.Greater))); // Print(Learn(g, l, ex("aab", "bb", Order.Less), ex("bb", "aab", Order.Greater))); // cannot be solved by length alone Print(Learn(g, l, ex("aab", "bb", Order.Greater), ex("bb", "aab", Order.Greater))); // sort by first character Print(Learn(g, l, ex("Neda Cerise", "Amit Willy", Order.Greater))); Print(g, "Oliver Mirele", "Neda Cerise", Learn(g, l, ex("Neda Cerise", "Amit Willy", Order.Greater), ex("Oliver Mirele", "Amit Willy", Order.Greater))); Print(Learn(g, l, ex("Neda Cerise", "Amit Willy", Order.Greater), ex("Oliver Mirele", "Amit Willy", Order.Greater), ex("Oliver Mirele", "Neda Cerise", Order.Greater))); Print(Learn(g, l, ex("Neda Cerise", "Amit Willy", Order.Greater), ex("Oliver Mirele", "Amit Willy", Order.Greater), ex("Oliver Mirele", "Neda Cerise", Order.Less))); }
/// <summary> /// To load the grammar file /// </summary> /// <param name="grammarFile">Location of the grammar file</param> /// <returns></returns> public static Grammar LoadGrammar(string grammarFile) { var compilationResult = DSLCompiler.ParseGrammarFromFile(grammarFile); if (compilationResult.HasErrors) { WriteColored(ConsoleColor.Magenta, compilationResult.TraceDiagnostics); throw new Exception(compilationResult.Exception.InnerException.Message); } if (compilationResult.Diagnostics.Count > 0) { WriteColored(ConsoleColor.Yellow, compilationResult.TraceDiagnostics); } return(compilationResult.Value); }
public SubmissionFixer(string pathToGrammar = @"..\..\..\Tutor\synthesis\", string pathToDslLib = @"..\..\Tutor\bin\debug") { ProsePrograms = new List <IEnumerable <ProgramNode> >(); UsedPrograms = new Dictionary <string, int>(); if (pathToDslLib == null) { pathToDslLib = "."; } if (pathToGrammar == null) { pathToGrammar = "../../../Tutor/synthesis/"; } grammar = DSLCompiler.ParseGrammarFromFile(pathToGrammar + @"Transformation.grammar", libraryPaths: new[] { pathToDslLib }); }
public static void Main(string[] args) { var parseResult = DSLCompiler.ParseGrammarFromFile("MatrixGrammar.grammar"); parseResult.TraceDiagnostics(); var grammar = parseResult.Value; Console.WriteLine(grammar.Name); //var ast = ProgramNode.Parse("matPlus(matPlus(M, M), M))", grammar, ASTSerializationFormat.HumanReadable); //double[] inp = new double[] { 2, 2, 1, 2, 3, 4 }; System.Random random = new System.Random(); double[] inp = new double[10002]; double[] opt = new double[10002]; inp[0] = 100; inp[1] = 100; opt[0] = 100; opt[1] = 100; for (int i = 2; i < 10002; i++) { double val = random.NextDouble(); inp[i] = val; // NextDouble already returns double from [0,1) opt[i] = 2 * val; } //double[] opt = new double[] { 2, 2, 2, 4, 6, 8 }; var input = State.Create(grammar.InputSymbol, inp); var spec = new ExampleSpec(new Dictionary <State, object> { [input] = opt }); //var engine = new SynthesisEngine(grammar); var engine = new SynthesisEngine(grammar, new SynthesisEngine.Config { Strategies = new ISynthesisStrategy[] { new DeductiveSynthesis(new MatrixLogic(grammar)), } }); ProgramSet learned = engine.LearnGrammar(spec); Console.Write(learned.Size); }
public static void Main(string[] args) { var parseResult = DSLCompiler.ParseGrammarFromFile("SortKeySynthesis.grammar"); parseResult.TraceDiagnostics(); var grammar = parseResult.Value; foreach (var d in parseResult.Diagnostics) { System.Console.WriteLine(d); } if (grammar == null) { Console.WriteLine("Grammar is null"); return; } testForwardExecution(grammar); testLearning(grammar); }