static void Main(string[] args) { raptor = new Interpreter(); ///*Registry*// //-------------------------------------------------------------------------------------------------------------------------------------- raptor.ActiveScope.AddFunction("~indexer", new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(Indexer_Fu)), "~index", "~enums"); raptor.ActiveScope.AddFunction("Set" , new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(Be_Fu)), "~value", "~id"); raptor.ActiveScope.AddFunction("Add" , new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(Add_Fu)), "~a", "~b"); raptor.ActiveScope.AddFunction("Clear" , new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(Clear_Fu))); raptor.ActiveScope.AddFunction("Pop" , new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(Pop_Fu))); raptor.ActiveScope.AddFunction("Print" , new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(Print_Fu)), "~toPrint"); raptor.ActiveScope.AddFunction("PrintL" , new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(PrintL_Fu)), "~toPrint"); raptor.ActiveScope.AddFunction("ReadFile", new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(ReadFile_Fu)), "~path"); raptor.ActiveScope.AddFunction("Eval" , new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(Eval_Fu)), "~string"); raptor.ActiveScope.AddFunction("ReadLine", new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(ReadLine_Fu))); //casting raptor.ActiveScope.AddFunction("list", new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(ListCast_Fu)), "items"); raptor.ActiveScope.AddFunction("int", new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(IntCast_Fu)), "toCast"); //Decloration raptor.ActiveScope.AddFunction("Def", new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(Def_Fu)), "~value", "~id"); raptor.ActiveScope.AddFunction("function", new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(DefMethod_Fu)), "~body" , "~paramList", "~id"); #if _DEBUG //DEBUGGING raptor.ActiveScope.AddFunction("Peek", new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(Peek_Fu))); raptor.ActiveScope.AddFunction("ActiveScope", new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(ActiveScope_Fu))); raptor.ActiveScope.AddFunction("HashCode", new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(HashCode_Fu)),"obj"); raptor.ActiveScope.AddFunction("Perent", new ReservedFunction(new ReservedFunction.ReservedFuncDelegate(Perent_Fu)), "obj"); #endif //------------------------------------------------------------------------------------------------------------------------------------------- if (args.Length == 0) { Console.WriteLine("BackScript Interapter Copyright (C) 2014 Nicodemes [email protected] \nThis program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n This is free software, and you are welcome to redistribute it\nunder certain conditions; type `show c' for details."); while (true) { Console.ForegroundColor = ConsoleColor.Blue; Console.Write("backScript"); Console.ForegroundColor = ConsoleColor.Green; Console.Write("$ "); Console.ForegroundColor = ConsoleColor.White; string row = Console.ReadLine(); LinkedList<object> tokens = null; try { try { nizer = new Tokenizer(row); tokens =nizer.Tokenize(); } catch (Exception e) { throw new Exception("Syntax Error: " + e.Message); } try { raptor.Process(tokens); } catch (Exception e) { throw new Exception("Interpritation Error: " + e.Message); } } catch (Exception e) { Console.WriteLine(" " + e.Message); raptor.Reset(); } } } else { System.IO.StreamReader myFile = new System.IO.StreamReader(args[0]); string myString = myFile.ReadToEnd(); myFile.Close(); string row = myString; LinkedList<object> tokens = null; try { try { nizer = new Tokenizer(row); tokens = nizer.Tokenize(); } catch (Exception e) { throw new Exception("Syntax Error: " + e.Message); }/* foreach (Token item in tokens) { Console.WriteLine("[" + item.type + "] " + item.lexema); }*/ try { raptor.Process(tokens); } catch (Exception e) { throw new Exception("Interpritation Error: " + e.Message); } } catch (Exception e) { Console.WriteLine(" " + e.Message); raptor.Reset(); } } }
static object Eval_Fu(SymbolTable s) { raptor.EnterScope(new SymbolTable(raptor.ActiveScope)); string row = s.GetValue(new Id("~string")) as string; LinkedList<object> tokens = null; try { try { nizer = new Tokenizer(row); tokens = nizer.Tokenize(); } catch (Exception e) { throw new Exception("Syntax Error: " + e.Message); }/* foreach (Token item in tokens) { Console.WriteLine("[" + item.type + "] " + item.lexema); }*/ try { raptor.Process(tokens); } catch (Exception e) { throw new Exception("Interpritation Error: " + e.Message); } } catch (Exception e) { Console.WriteLine(" "+e.Message); raptor.Reset(); } raptor.ScopeOut(); return new Void(); }