/// <summary> /// Driver routine to call the program script /// </summary> static void TestFileScript(string filename) { if (filename == null) { return; } // -------------- Read the contents from the file StreamReader sr = new StreamReader(filename); string programs2 = sr.ReadToEnd(); //---------------- Creates the Parser Object // With Program text as argument RDParser pars = null; pars = new RDParser(programs2); TModule p = null; p = pars.DoParse(); if (p == null) { Console.WriteLine("Parse Process Failed"); return; } // // Now that Parse is Successul... // Do a recursive interpretation...! // RUNTIME_CONTEXT f = new RUNTIME_CONTEXT(p); SYMBOL_INFO fp = p.Execute(f); }
/// <summary> /// Driver routine to call the program script /// </summary> static void TestFileScript(string filename) { if (filename == null) { return; } // -------------- Read the contents from the file StreamReader sr = new StreamReader(filename); string programs2 = sr.ReadToEnd(); sr.Close(); sr.Dispose(); //---------------- Creates the Parser Object // With Program text as argument RDParser pars = null; pars = new RDParser(programs2); TModule p = null; p = pars.DoParse(); // // Now that Parse is Successul... // Create an Executable...! // if (p.CreateExecutable("First.exe")) { Console.WriteLine("Creation of Executable is successul"); return; } }
public TrackingShot Load() { string shotstr = SettingsStore.Get <string>(Entity, "shot", null); if (shotstr == null) { return(new TrackingShot()); } var parser = new RDParser(shotstr); parser.Expect("Position"); parser.Expect(":"); var position_timeline = Timeline.Deserialize(parser); parser.Expect(","); parser.Expect("LookAt"); parser.Expect(":"); var lookat_timeline = Timeline.Deserialize(parser); parser.Expect(","); parser.Expect("UpVec"); parser.Expect(":"); var upvec_timeline = Timeline.Deserialize(parser); parser.End(); return(new TrackingShot(position_timeline, lookat_timeline, upvec_timeline)); }
/// <summary> /// /// </summary> static void TestSecondScript() { string a = "PRINTLINE -2*10;" + "\r\n" + "PRINTLINE -10*-1;\r\n PRINT 2*10;\r\n"; RDParser p = new RDParser(a); ArrayList arr = p.Parse(); foreach (object obj in arr) { Stmt s = obj as Stmt; s.Execute(null); } }
//Function: Main //Purpose: Main function of the program. Also serves as the driver for the program static void Main(string[] args) { string oberon_file = debug_directory + DecodeArguments(args); RDParser parser = new RDParser(oberon_file); parser.Parse(); // Hold the output until the user wants to end the program. Console.Write("Press a key to end... "); Console.ReadKey(); }
/// <summary> /// Driver routine to call the program script /// </summary> static void TestFileScript(string filename) { if (filename == null) { return; } // -------------- Read the contents from the file StreamReader sr = new StreamReader(filename); string programs2 = sr.ReadToEnd(); //---------------- Creates the Parser Object // With Program text as argument RDParser pars = null; pars = new RDParser(programs2); // Create a Compilation Context // // COMPILATION_CONTEXT ctx = new COMPILATION_CONTEXT(); // // Call the top level Parsing Routine with // Compilation Context as the Argument // ArrayList stmts = pars.Parse(ctx); // // if we have reached here , the parse process // is successful... Create a Run time context and // Call Execute statements of each statement... // RUNTIME_CONTEXT f = new RUNTIME_CONTEXT(); foreach (Object obj in stmts) { Stmt s = obj as Stmt; s.Execute(f); } }
static void Main(string[] args) { string input; using (var sr = new StreamReader("program.txt", Encoding.UTF8)) { input = sr.ReadToEnd(); } List <Token> tokens = new Lexer(input).Tokenize(); foreach (var token in tokens) { Console.WriteLine(token); } Statement program = new RDParser(tokens).Parse(); Console.WriteLine(program.ToString()); program.Execute(); Console.ReadKey(); }
/// <summary> /// Generate the JavaScript for the Eligibility rules... /// </summary> /// <param name="slang_text"></param> /// <returns></returns> public bool GenerateJSRuleEligible(string slang_text) { //---------------- Creates the Parser Object // With Program text as argument RDParser pars = null; pars = new RDParser(slang_text); _eligible_rules = pars.DoParse(); if (_eligible_rules == null) { Console.WriteLine("Parse Process Failed while processing Eligibility rules"); return(false); } // // Now that Parse is Successul... // Generate JavaScript // RUNTIME_CONTEXT f = new RUNTIME_CONTEXT(_eligible_rules); SYMBOL_INFO fp = _eligible_rules.GenerateJS(f, null); return(true); }
/// <summary> /// /// </summary> /// <param name="ruletab"></param> /// <param name="compiled_so_far"></param> /// <returns></returns> String EmitRuleSnippets(String ruletab, String compiled_so_far) { DataSet ds = m_reader.GetData(ruletab); if (ds == null) { return(null); } DataTable dt = ds.Tables[0]; if (dt == null) { return(null); } int Count = dt.Rows.Count; int i = 0; String rs = "//------- Rule for Programs " + ruletab + "\r\n\r\n"; String FuncText2 = ""; while (i < Count) { DataRow dr = dt.Rows[i]; String RuleFunction = Convert.ToString(dr["Rule Name"]); i++; if (RuleFunction == null || RuleFunction == "") { continue; } FuncText2 = RuleFunction; String RuleBody = Convert.ToString(dr[1]); if (RuleBody == null || RuleBody == "") { continue; } rs += "// --- " + RuleFunction + "\r\n"; List <String> rst = SplitLines(RuleBody); foreach (String s in rst) { rs += "//-------- " + s + "\r\n"; } //----------- Generate the Rule Prolog //----------- //----------- String Splitbody = ""; foreach (String st in rst) { Splitbody += st + "\r\n"; } String FuncText = GenerateRuleProlog(RuleFunction, Splitbody); if (FuncText == null) { Console.WriteLine("Failed to Compile Rule " + FuncText2 + " in " + ruletab); Console.WriteLine("====================================="); rule_compile_flag = false; } RDParser par = new RDParser(compiled_so_far + "\r\n" + rs + "\r\n" + FuncText); TModule module = par.DoParse(); if (module == null) { Console.WriteLine("Failed to Compile Rule " + FuncText2 + " in " + ruletab); Console.WriteLine("====================================="); rule_compile_flag = false; } else { rs += FuncText + "\r\n\r\n\r\n"; } } if (rule_compile_flag == false) { return(null); } return(compiled_so_far + rs); }
/// <summary> /// /// </summary> /// <returns></returns> String EmitFunctions() { DataSet ds = m_reader.GetData("FUNCTIONS$"); if (ds == null) { return(null); } DataTable dt = ds.Tables[0]; if (dt == null) { return(null); } int Count = dt.Rows.Count; int i = 0; String rs = "//------- Function spit from Functions Tab \r\n\r\n"; while (i < Count) { DataRow dr = dt.Rows[i]; String FunctionBody = Convert.ToString(dr[1]); i++; if (FunctionBody == null || FunctionBody == "") { continue; } rs += "// --- " + dr[0] + "\r\n"; List <String> rst = SplitLines(FunctionBody); foreach (String s in rst) { rs += "//-------- " + s + "\r\n"; } //----------- Generate the Rule Prolog //----------- //----------- String Splitbody = ""; foreach (String st in rst) { Splitbody += st + "\r\n"; } RDParser par = new RDParser(rs + Splitbody); TModule module = par.DoParse(); if (module == null) { Console.WriteLine("//Failed to Compile Rule " + dr[0]); Console.WriteLine("//====================================="); rule_compile_flag = false; } else { rs += Splitbody + "\r\n\r\n\r\n"; } } if (rule_compile_flag == false) { return(null); } return(rs); }
/// <summary> /// /// </summary> /// <param name="p"></param> /// <param name="slang_text"></param> /// <returns></returns> public string EmitProgramToRuleMappings(string p, string slang_text) { ///////////////////////////////////////////// // // Retrieve the data from Excel Reader... DataSet ds = m_reader.GetData(p); if (ds == null) { return(null); } //////////////////////////////////////// // // Get the Worksheet data... // DataTable dt = ds.Tables[0]; Dictionary <String, SYMBOL_INFO> ret = new Dictionary <string, SYMBOL_INFO>(); if (dt == null) { return(null); } int Count = dt.Rows.Count; slang_text += "//----------- Program To Rule mapping \r\n\r\n"; int i = 0; while (i < Count) { DataRow dr = dt.Rows[i]; try { if (dr["RULETEXT"] == null || dr["PROGRAMNAME"] == null) { return(null); } } catch (Exception e) { Console.WriteLine("The Cell Column name should be PROGRAMNAME , RULETEXT in " + p); return(null); } String FunctionName = Convert.ToString(dr["PROGRAMNAME"]); String FunctionBody = Convert.ToString(dr["RULETEXT"]); List <String> rst = SplitLines(FunctionBody); string new_prog = ""; foreach (String s in rst) { new_prog += s + "\r\n"; } string program_text = ManufactureFunction(FunctionName, new_prog); i++; /////////////////////////////// // CSnippetParser is a subclass of RDParser the purpose is to parse // PROGRAM_TO_RULE snippets... // // CSnippetParser par = new CSnippetParser(program_text, rule_sym); TModule mod = par.ParseText(); if (mod == null) { Console.WriteLine("Error in Parsing " + FunctionName + " in " + "PROGRAM_TO_RULE \r\n"); rule_compile_flag = false; } else { Dictionary <string, SYMBOL_INFO> inf = par.GetLocals(); program_text = ManufactureFunctionWithParams(inf, FunctionName, new_prog); RDParser par2 = new RDParser(program_text); mod = par2.DoParse(); if (mod == null) { Console.WriteLine("Error in Parsing " + FunctionName + " in " + "PROGRAM_TO_RULE \r\n"); rule_compile_flag = false; } else { slang_text += "\r\n" + program_text + "\r\n"; } } } return(slang_text); }
static void TestFileScript(string filename) { if (filename == null) { return; } // -------------- Read the contents from the file StreamReader sr = new StreamReader(filename); string programs = sr.ReadToEnd(); sr.Close(); sr.Dispose(); //---------------- Creates the Parser Object // With Program text as argument RDParser pars = null; pars = new RDParser(programs); //Fib.SL TModule p = null; p = pars.DoParse(); if (p == null) { Console.WriteLine("Parse Process Failed "); return; } // // Now that Parse is Successul... // Create an Executable...! if (p.CreateExecutable("outPut.exe")) { Console.WriteLine("Creation of Executable is successul"); // Save the Assembly and generate the MSIL code with ILDASM.EXE string modName = "outPut.exe"; Process process = new Process(); process.StartInfo.FileName = "ildasm.exe"; process.StartInfo.Arguments = "/text /nobar \"" + modName; process.StartInfo.UseShellExecute = false;// set false if u want to use RedirectStandardOutput Property process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start(); string s = process.StandardOutput.ReadToEnd(); Console.WriteLine(s); string[] fname = modName.Split('.'); System.IO.StreamWriter file = new System.IO.StreamWriter(fname[0] + ".txt"); file.WriteLine(s); file.Close(); ////// //Console.ReadLine(); process.WaitForExit(); process.Close(); return; } }
public static Timeline Deserialize(RDParser parser) { Timeline timeline = new Timeline(); while (true) { long frame = 0; TrackingInfo info = new TrackingInfo(); if (!parser.Accept("[")) { break; } if (!parser.GetLong(ref frame)) { parser.Fail("frame expected"); } parser.Expect(":"); if (parser.Accept("Locked")) { info.Mode = TrackMode.Locked; } else if (parser.Accept("Unlocked")) { info.Mode = TrackMode.Unlocked; } else { parser.Fail("unknown track mode"); } parser.Expect(":"); if (info.Mode == TrackMode.Locked) { if (!parser.GetLong(ref info.EntityId)) { parser.Fail("entity id expected"); } } parser.Expect(":"); parser.Expect("<"); if (!parser.GetDouble(ref info.Value3D.X)) { parser.Fail("vector x expected"); } parser.Expect(","); if (!parser.GetDouble(ref info.Value3D.Y)) { parser.Fail("vector y expected"); } parser.Expect(","); if (!parser.GetDouble(ref info.Value3D.Z)) { parser.Fail("vector z expected"); } parser.Expect(">"); parser.Expect(":"); if (parser.Accept("Constant")) { info.Transition = TransitionMode.Constant; } else if (parser.Accept("Linear")) { info.Transition = TransitionMode.Linear; } else if (parser.Accept("Cosine")) { info.Transition = TransitionMode.Cosine; } else if (parser.Accept("Spline")) { info.Transition = TransitionMode.Spline; } else { parser.Fail("unknown transition mode"); } parser.Expect("]"); timeline.keyframes.Add((int)frame, info); } return(timeline); }