/// <summary> /// Evaluates conditions /// </summary> /// <param name="Condition">Condition.</param> /// <param name="screen">Screen.</param> /// <param name="Spaces">Spaces.</param> public static void Eval (List <string> condition, ref CodeScreen screen, ref DataTable spaces) { bool whilesign = true; if (condition.Count == 2 || condition.Count == 3){ if (Space.Calculate (condition [0], ref spaces, screen) != "False") { Arendelle condiotoncode = new Arendelle (condition [1]); Kernel.Eval (ref condiotoncode, ref screen, ref spaces, ref whilesign); } else { if (condition.Count == 3) { Arendelle condiotoncode = new Arendelle (condition [2]); Kernel.Eval (ref condiotoncode, ref screen, ref spaces, ref whilesign); } } } else { Reporter.Throw ("Condition must contain 2 or 3 parts", screen); } }
/// <summary> /// Replacer for Stored Spaces /// </summary> /// <returns>The space replacer.</returns> /// <param name="StoredSpaceName">Stored space name.</param> /// <param name="screen">Screen.</param> public static string StoredSpaceReplacer(string storedSpaceName, CodeScreen screen) { string name = Mermaid.Text.RemoveStart (storedSpaceName, "$"); string spacePath = Paths.PathGenerator (name , "space", screen); string space = ""; if (File.Exists (spacePath)) { try { using (StreamReader reader = new StreamReader (spacePath)) { space = reader.ReadToEnd (); reader.Close (); } } catch { Reporter.Throw ("Could not load stored space: '" + storedSpaceName + "'.", screen); } } else { Reporter.Throw ("No stored space as '" + storedSpaceName + "' found.", screen); } return space; }
public static void EvaluatedMain(string code, string mainPath) { Console.Title = " "; if (code != "BadFile") { Console .Clear (); CodeScreen screen = new CodeScreen (mainPath, "SHELL"); screen.OpenedByArgs = true; try { MasterEvaluator.Evaluate (code, screen); //Console .Beep (); } catch { Reporter.Throw ("Something bad happend...", screen); } IDEInterface.TheA6 (""); Console.Clear (); Environment.Exit ( 0 ); } }
/// <summary> /// Shows the erros. /// </summary> /// <param name="message">Message.</param> /// <param name="screen">Screen.</param> public static void ShowErros(string message, CodeScreen screen) { Console .Clear (); int line = screen.line; if (screen.line2 != 0) line = screen.line2; string pathAndNameString = ""; if (screen.FuncName != "SHELL") { pathAndNameString = "Line:" + line + " Function: " + screen.FuncName; } else { if (screen.MainPath != "SHELL") pathAndNameString = "Line:" + line; } CenterWriter (-1, "ERROR: " + message); InterfaceView.ConsoleKeyPress (pathAndNameString); if (screen.OpenedByArgs) { IDEInterface.Shutdown(); } else Interface.RealMain (); //Console .SetCursorPosition ( Console .WindowWidth - 1 , Console .WindowHeight -1 ); //Console .ReadKey (); }
/// <summary> /// Clears the specified screen. /// </summary> /// <param name="screen">Screen.</param> public static void Clear(CodeScreen screen) { if (screen.x >= 0 && screen.y >= 0 && (screen.x) < Console.WindowWidth && screen.y < Console.WindowHeight - 1) { Console.SetCursorPosition (int.Parse (screen.x.ToString ()), int.Parse (screen.y.ToString ())); Console .Write (" "); } Console .SetCursorPosition (Console .WindowWidth -1,Console .WindowHeight -1); }
/// <summary> /// Returns a string inside one arendelle file /// </summary> /// <param name='Command'> /// file's address /// </param> public static string read(string command, CodeScreen screen) { string movePath = Mermaid.Text.RemoveStart (command, "open ").TrimEnd ().TrimStart (); if ( File .Exists (movePath)){ if ( movePath.ToLower().EndsWith (".arendelle")) { try { using (StreamReader MoveReader = new StreamReader ( movePath )) { return MoveReader.ReadToEnd (); } } catch { return "BadFile"; } } else { Reporter.Throw ("Your file is not signed as '.arendelle'.", screen); return "BadFile"; } } else { movePath = movePath + ".arendelle"; if ( movePath.ToLower().EndsWith (".arendelle")) { try { using ( StreamReader MoveReader = new StreamReader (movePath)) { return MoveReader.ReadToEnd (); } } catch { return "BadFile"; } } else { Reporter.Throw ("The file does not exists.", screen); return "BadFiles"; } } }
/// <summary> /// Paint command's code. /// </summary> /// <param name="screen">Screen.</param> public static void Paint(CodeScreen screen) { string colors = "█▓▒░"; if (screen.x >= 0 && screen.y >= 0 && (screen.x) < Console.WindowWidth && screen.y < Console.WindowHeight - 1) { Console.SetCursorPosition (int.Parse (screen.x.ToString ()), int.Parse (screen.y.ToString ())); Console .Write (colors[screen.color].ToString()); } Console .SetCursorPosition (Console .WindowWidth -1,Console .WindowHeight -1); }
/// <summary> /// Checks for upades. /// </summary> public static void Check() { string updateInfo = ""; CodeScreen screen = new CodeScreen ("SHELL", "SHELL"); Console .Clear (); InterfaceView.CenterWriter (-2, "Connecting to the Arendelle's safe servers..."); InterfaceView.CenterWriter (-1, "Do not press any button "); try { using (WebClient client = new WebClient ()) { updateInfo = client.DownloadString ("http://client-information-server.arendelle.org/update-info/arcade.update"); } } catch { //System.Media.SystemSounds.Beep.Play(); Reporter.Throw ("Can not connect to the server at this time.", screen); } int releaseNumber = int.Parse (Mermaid.Text.ReadTag (updateInfo, "release")); if (releaseNumber > InterfaceView.OnlineReleaseNumber ()) { string newArcadeVersion = Mermaid.Text.ReadTag (updateInfo, "arcade"); string newArendelleVersion = Mermaid.Text.ReadTag (updateInfo, "arendelle"); string newGeneralVersion = Mermaid.Text.ReadTag (updateInfo, "general"); Console.Clear (); InterfaceView.CenterWriter (-2, "There is a new version available ( #" + releaseNumber + " ~ " + newGeneralVersion + " ) :"); InterfaceView.CenterWriter (-1, "Arcade Version: " + newArcadeVersion + " / Arendelle Version: " + newArendelleVersion + " ~ Release No." + releaseNumber); } else { Console.Clear (); InterfaceView.CenterWriter (-2, "You are using the very latest version!"); } InterfaceView.ConsoleKeyPress (""); Interface.RealMain (); }
/// <summary> /// Comment's that start with // and ends with an enter /// </summary> /// <param name="arendelle">Arendelle.</param> /// <param name="screen">Screen.</param> public static void slashslashenter(ref Arendelle arendelle, ref CodeScreen screen) { string command = ""; while (arendelle .i < arendelle .code .Length) { command = arendelle.code [arendelle.i].ToString (); if (command == "\n" || command == "" || command == null) { screen.line++; break; } else { arendelle.i++; } } }
/// <summary> /// Eval the specified movescreen, codes, PublicVars and PrivateVars. /// </summary> /// <param name='movescreen'> /// Movescreen. /// </param> /// <param name='codes'> /// Codes. /// </param> /// <param name='PublicVars'> /// Public variables. /// </param> /// <param name='PrivateVars'> /// Private variables. /// </param> public static string eval(List<string> codes, ref DataTable spaces, CodeScreen screen) { string toBeReturned = ""; if ( codes [0].TrimStart ().StartsWith ("$")) { StoredSpaceEval (codes, ref spaces, screen); } else { toBeReturned = SpaceEval (codes, ref spaces, screen); } return toBeReturned; }
/// <summary> /// Checks the name of the space. /// </summary> /// <param name='name'> /// Name. /// </param> /// <param name='screen'> /// Screen. /// </param> public static void CheckSpaceName(string name, ref CodeScreen screen) { name = name.TrimStart().TrimEnd(); var reg = Regex.Matches (name, "[A-z]*([A-z]|[0-9])+"); if (reg.Count > 0) { if (reg [0].ToString() != name) { Reporter.Throw ("Unaccpeted space name '"+name+"'.", screen ); } } }
/// <summary> /// Generates a random number in the format of "0.XXXXX" /// </summary> /// <returns>The gerator.</returns> /// <param name="screen">Screen.</param> public static string RNDFGerator(CodeScreen screen) { int rndInt = screen.rand.Next (100, 100000); double rndBool = Math.Floor (Math.Log10 (double.Parse (rndInt.ToString ()))); if (rndBool == 3) { return "0.0" + rndInt.ToString (); } else if (rndBool == 2){ return "0.00" + rndInt.ToString (); } else { return "0." + rndInt.ToString (); } }
public static string PathGenerator(string name, string filetype, CodeScreen screen) { // // Paths in Unix are like this: // ./Arendelle/Samples // // But in Windows systems they are // like: // c:\Windows\Program Files\Arendelle\Samples // // What we want to generate a path from making "shapes.m1" // that should be like this ( assuming our path is /home/main // ==> /home/main/shapes/m1.arendelle // string funcRep; string osSpecificDirectorySign = ""; OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; if (pid == PlatformID.Unix || pid == PlatformID.MacOSX) { osSpecificDirectorySign = "/"; } else if (pid == PlatformID.Win32NT || pid == PlatformID.Win32S || pid == PlatformID.Win32Windows || pid == PlatformID.WinCE || pid == PlatformID.Xbox) { osSpecificDirectorySign = "\\"; } else { CodeScreen tempScreen3 = new CodeScreen ( "SHELL" , "SHELL" ); Reporter.Throw ("Your OS does not support Functions",tempScreen3); return "BadFuncName"; } funcRep = name.Replace (".", osSpecificDirectorySign); return screen.MainPath + osSpecificDirectorySign + funcRep + "." + filetype; }
public static string CommentRemover(string code, CodeScreen screen) { Arendelle tempArendelle = new Arendelle (code); string codeWithNoComment = ""; while (tempArendelle.i < tempArendelle.code.Length) { string command = tempArendelle.code [tempArendelle.i].ToString (); if (command == "/") { command = tempArendelle.code [tempArendelle.i + 1].ToString (); if (command == "*") { tempArendelle.i = comments.slashstar (ref tempArendelle, ref screen) + 1; } else if (command == "/") { comments.slashslashenter (ref tempArendelle, ref screen); } else { codeWithNoComment = codeWithNoComment + "/"; tempArendelle.i ++; } } else { codeWithNoComment = codeWithNoComment + command; tempArendelle.i ++; } } return codeWithNoComment; }
/// <summary> /// The very main evaluator that runs a given code with the screen. /// </summary> /// <param name="code">Code.</param> /// <param name="screen">Screen.</param> public static void Evaluate(string code, CodeScreen screen) { // // comment remover // string codeWithNoComment = MasterEvaluator.CommentRemover (code, screen); // // setting up the spaces // DataTable spaces = new DataTable ("spaces"); spaces.Columns.Add ("name"); spaces.Columns.Add ("space"); // // setting up the WhileSign // bool Sign = true; // // setting up the Arendelle // Arendelle arendelle = new Arendelle ( codeWithNoComment ); ////////////////// /// EVALUATING /// ////////////////// IDEInterface.StatingTitleRemover (); InterfaceView.SetArendelleTitle (); // // running // Kernel.Eval (ref arendelle, ref screen, ref spaces, ref Sign); }
/// <summary> /// Waits /// </summary> /// <param name="screen">Screen.</param> public static void Wait(CodeScreen screen) { Console .SetCursorPosition (Console .WindowWidth -1,Console .WindowHeight -1); System .Threading.Thread.Sleep (1); Console .SetCursorPosition (int.Parse(screen.x.ToString()),int.Parse(screen.y.ToString())); }
/// <sumary> /// This is the Loop.Eval kernel, where it runns the given loop. /// </summary> /// <param name='Code'> /// Code the given loop /// </param> /// <param name='i'> /// I. /// </param> /// <param name='X'> /// X. /// </param> /// <param name='Y'> /// Y. /// </param> /// <param name='Color'> /// Color. /// </param> public static void LoopParser (ref Arendelle arendelle, ref CodeScreen screen, ref DataTable spaces) { /* * We make a String List to collect the parts of the Open-Close grammars * like the grammar of the loop where we open it with a "[" and close it * with a "]". the Lexings.OpenCloseLexer reads the grammar and returns a * collections of parts like: * * [ 20 , rc ] => { "20" , "rc" } * [ 20 , [ 20 , [ 20 , rc ] ] ] => { "20" , "[20,[20,rc]]" } * * So remember: * 1) If there be more than one grammar part it the lexer will return more * all of them like: * * [ 20 , 30 , 40 , 50 ] => { "20" , "30" , "40" , "50" } * * 2) If we are reading a broken grammar like: * * [ 20 , 20 * * the lexer will change the first entry from anything to "BadGrammar" * like: * * [ 20 , 30 , 40 => { "BadGrammar" , "30" } */ List < string > loop = Lexers.OpenCloseLexer ("[", ref arendelle, ref screen); // // So we have to see if what we have is not broken, missing or overloaded: // if (loop.Count == 2 && loop [0] != "BadGrammar"){ // // Soon we will parse the Loop [ 0 ] which is the string of the loop // number into this value. // // // User may have typed the code wrong so will have a huge // crash on the program becuase the system can not parse it into // a int number and we can not let it happen it's why we run it // on a try system. // try { string calculatedLoopNumber = Space.Calculate (loop[0], ref spaces, screen); if (calculatedLoopNumber == "True") { bool whileSign = true; int lines = loop[1].Length - loop[1].Replace ("\n","").Length; while (whileSign == true && screen.WhileSign == true) { int j = 0; Arendelle loopCode = new Arendelle (loop [1]); loopCode.i = j; Kernel.Eval (ref loopCode, ref screen, ref spaces, ref whileSign); screen.line = screen.line - lines; if (Space.Calculate (loop[0], ref spaces, screen) != "True") whileSign = false; } screen .WhileSign = true; } else if ( calculatedLoopNumber == "False") { // // Simply goes out. // } else { int j = 0; decimal decimalNumber = Math.Floor (decimal.Parse(calculatedLoopNumber)); int lines = loop[1].Length - loop[1].Replace ("\n","").Length; for ( decimal k = 0; k < decimalNumber; k++ ) { j = 0; // // We run any given code using the Kernels' Eval core because // it can run any code. the good part is it can run in itself // so we can handle loops inside loops thanks to this tech. // Arendelle loopMove = new Arendelle (loop [1]); loopMove.i = j; bool WhileSign = true; screen.line = screen.line - lines; Kernel.Eval (ref loopMove, ref screen, ref spaces, ref WhileSign); } } } catch { Reporter.Throw ("Bad Loop Number: '" + loop[0] + "'", screen); } // // Now it's time to run the loop. // // // In case of broken code. // } else if (loop[0] == "BadGrammar") { Reporter.Throw ("Unknown broken loop found.", screen); // // In case of missing or overloaded code. // } else { Reporter.Throw ("Loop with one or more than two parts", screen); } }
/// <summary> /// Evaluates Stored Spaces /// </summary> /// <param name="codes">Codes.</param> /// <param name="Spaces">Spaces.</param> /// <param name="screen">Screen.</param> public static void StoredSpaceEval(List<string> codes, ref DataTable spaces, CodeScreen screen) { if (screen.MainPath == "SHELL") Reporter.Throw ("You can not use stored spaces inside interactive shell.", screen); string name = Mermaid.Text.RemoveStart (codes [0].TrimStart().TrimEnd(), "$"); string spacePath = Paths.PathGenerator (name, "space", screen); string space = ""; if (codes.Count == 2) { codes [1] = codes [1].TrimStart ().TrimEnd(); if ( codes [1].StartsWith ("\"")) { Arendelle askText = new Arendelle (codes [1]); string text = Lexers.OnePartOpenCloseParser ("\"", ref askText, ref screen); space = Space.Calculate (IDEInterface.AskNumber (text), ref spaces, screen); } else if (codes [1].StartsWith ("/") || codes [1].StartsWith ("*") || codes [1].StartsWith ("+") || codes [1].StartsWith ("-")) { space = Space.Calculate (name + codes [1], ref spaces, screen); } else if (codes [1] == "done") { try { if (File.Exists (spacePath)) File.Delete (spacePath); } catch { Reporter.Throw ("Can not remove stored space '" + name + "'", screen); } } else { space = Space.Calculate (codes [1], ref spaces, screen); } } else if (codes.Count == 1) { string text = "Sign stored space '" + name + "' with a number:"; space = Space.Calculate (IDEInterface.AskNumber (text), ref spaces, screen); } try { using (StreamWriter spaceWriter = new StreamWriter (spacePath)) { spaceWriter.Write (space); spaceWriter.Close (); } } catch { Reporter.Throw ("Could not store space '" + space + "' into '" + spacePath + "'", screen); } }
/// <summary> /// Breaks down the Arendelle function grammar into a list<string> /// </summary> /// <param name='arendelle'> /// Arendelle. /// </param> /// <param name='screen'> /// Screen. /// </param> public static List<string> Parser(ref Arendelle arendelle, CodeScreen screen) { var functionGrammarCollection = new List<string> { }; functionGrammarCollection.Add (""); bool whilebool = true; string funcName = ""; string command = ""; List<string> functionSpaces = new List<string> { }; while (whilebool) { if (arendelle.i > arendelle.code.Length) { Reporter.Throw ("Function without: (...)",screen); functionGrammarCollection [0] = "BadFuncName"; return functionGrammarCollection; } else { arendelle.i ++; command = arendelle.code [arendelle.i].ToString (); } switch (command) { case "(": functionSpaces = Lexers.OpenCloseLexer ("(", ref arendelle, ref screen); functionGrammarCollection.AddRange (functionSpaces); whilebool = false; break; case ")": Reporter.Throw ("Wrong function grammar.", screen); functionGrammarCollection [0] = "BadFuncName"; break; case "\n": Reporter.Throw ("Unaccepted use of new line in function name", screen); functionGrammarCollection [0] = "BadFuncName"; break; default: funcName = funcName + command; break; } } funcName = funcName.TrimEnd ().TrimStart (); var nameCollection = Regex.Matches (funcName, "[A-z]([A-z]|[0-9]|\\.)+([A-z]|[0-9])*"); if (nameCollection.Count == 1) { if (nameCollection [0].ToString () == funcName) { functionGrammarCollection [0] = funcName; return functionGrammarCollection; } else { Reporter.Throw ("Function name not accepted.", screen); functionGrammarCollection [0] = "BadFuncName"; return functionGrammarCollection; } } else { Reporter.Throw ("Function name with more than one part.", screen); functionGrammarCollection [0] = "BadFuncName"; return functionGrammarCollection; } }
/// <summary> /// Replacer the specified expr, PublicVards and PrivateVars. /// </summary> /// <param name='expr'> /// Expr. /// </param> /// <param name='PublicVards'> /// Public vards. /// </param> /// <param name='PrivateVars'> /// Private variables. /// </param> public static string replacer(string expr, ref DataTable spaces, CodeScreen screen) { // // Engine.Lexers.Lexers.cs // List<string> openedExpr = Lexers.ExpressionAnalyzer (expr, ref screen); string final = ""; foreach (string value in openedExpr) { // // Values that starts with @ are varieables of the language // and we must give them their values before evaluating them // which we do with replacing them with their values. // string toBeReplaced = ""; if (value.StartsWith("#")) { switch (value) { case "#x": toBeReplaced = screen.x.ToString (); break; case "#y": toBeReplaced = screen.y.ToString (); break; case "#z": toBeReplaced = screen.z.ToString (); break; case "#pi": toBeReplaced = Math.PI.ToString (); break; case "#j": toBeReplaced = IDEInterface.ScreenH (); break; case "#i": toBeReplaced = IDEInterface.ScreenW (); break; case "#width": toBeReplaced = IDEInterface.ScreenW (); break; case "#height": toBeReplaced = IDEInterface.ScreenH (); break; case "#k": toBeReplaced = IDEInterface.ScreenV (); break; case "#n": toBeReplaced = screen.color.ToString (); break; case "#rnd": toBeReplaced = ArendelleMathLib.RNDFGerator (screen); break; default: Reporter.Throw ("Unknown source: '" + value +"' found.", screen); break; } } else if (value.StartsWith ("@")){ try { DataRow[] rows = spaces.Select ("name = '" + value + "'"); if (rows.Length == 0) Reporter.Throw ("Unsigned space '" + value + "' found.", screen); else { if (rows[0][1].ToString() != "") toBeReplaced = rows[ 0 ][ 1 ].ToString(); else Reporter.Throw ("Unsigned space '" + value + "' found.", screen); } } catch (Exception ex) { Reporter.Throw (ex.Message.ToString (), screen); } } else if (value.StartsWith ("$")){ string name = Mermaid.Text.RemoveStart (value, "$"); string spacePath = Paths.PathGenerator (name, "space", screen); if (File.Exists (spacePath)){ try { using (StreamReader reader = new StreamReader (spacePath)){ toBeReplaced = reader.ReadToEnd(); reader.Close(); } } catch { Reporter.Throw ("Could not load stored space: '" + value + "'.", screen); } } else { Reporter.Throw ("No stored space as '" + value + "' found.", screen); } } else if (value.StartsWith ("!")){ Arendelle funcArendelle = new Arendelle (value); bool whilesign = true; toBeReplaced = FunctionEVAL.EVAL (ref funcArendelle, ref screen, ref spaces, ref whilesign); } else { toBeReplaced = value; } final = final + toBeReplaced; } return final; }
/// <summary> /// This systems opens and ends with one char line a string that opens and ends with '"' and /// we are not going to sprate parts with ',' on it. /// </summary> /// <param name='OpenCloseCommand'> /// Open and Close command /// </param> /// <param name='arendelle'> /// Arendelle code that contains the grammar. /// </param> /// <param name='screeen'> /// Screeen. /// </param> public static string OnePartOpenCloseParser (string openCloseCommand, ref Arendelle arendelle, ref CodeScreen screeen) { // // for reporting // screeen.line2 = screeen.line; // // going to the next char. // arendelle.i++; // // we collect our resualt here. // string result = null; // // now for 1=1 we go right until we find something and break out. // while (true) { // // the char that we are reeading. // string command = arendelle.code [arendelle.i] .ToString (); // // is it close part? // if (command == openCloseCommand) { arendelle.i ++; return result; } else if (command == "\\") { arendelle.i ++; command = arendelle.code [arendelle.i] .ToString (); switch (command) { case "\"" : result = result + "\""; break; case "'" : result = result + "'" ; break; case "%" : result = result + "%" ; break; default: result = result + "\\" + arendelle.code [arendelle.i] .ToString (); break; } // // should we count new line? // } else if (command == "\n") { screeen.line ++; result = result + "\n"; // // or we have to add the command // } else { result = result + command; } // // is there any next command to parse? // if ( arendelle.i < arendelle.code .Length ) { arendelle.i ++; } else { // // no the grammar is not closed! // Reporter.Throw ("Unfinished " + openCloseCommand + "..." + openCloseCommand + " grammar", screeen); return "BadGrammar"; } } }
public static void OpenFileMain(string filePath) { Console.Title = " "; string mainPath = Path.GetDirectoryName (filePath); // // THIS IF IS TEMP AND NEEDS CHANGE // if (mainPath == "") mainPath = "."; CodeScreen tempScreen10 = new CodeScreen ("SHELL", "SHELL"); tempScreen10.OpenedByArgs = true; string code = ArendelleFile.read (filePath, tempScreen10); if (code != "BadFile") { Console.Clear (); CodeScreen screen = new CodeScreen (mainPath, "SHELL"); screen.OpenedByArgs = true; try { InterfaceView.SetArendelleTitle (); MasterEvaluator.Evaluate (code, screen); //Console .Beep (); } catch { Reporter.Throw ("Something bad happend...", screen); } IDEInterface.TheA6 (""); IDEInterface.Shutdown (); } else { CodeScreen tempScreen12 = new CodeScreen ("SHELL", "SHELL"); tempScreen12.OpenedByArgs = true; Reporter.Throw ("Bad file: file type is not accepted or file/directory does not exists.", tempScreen12); IDEInterface.Shutdown (); } }
public static void RealMain() { Start: InterfaceView.SetMainMenu (); string mainPath = "SHELL"; Console.Write ("λ "); string code = Console.ReadLine (); if (code.ToLower ().TrimEnd ().TrimStart () == "exit") { IDEInterface.Shutdown (); } else if (code == "about") { InterfaceView.AboutPage (); } else if (code == "update") { Update.Check (); } else if (code.StartsWith ("open ")) { mainPath = Path.GetDirectoryName (Mermaid.Text.RemoveStart (code, "open ")); CodeScreen tempScreen11 = new CodeScreen ("SHELL", "SHELL"); code = ArendelleFile.read (code , tempScreen11); if (code == "BadFile") { CodeScreen TempScreen1 = new CodeScreen ("SHELL", "SHELL"); Reporter.Throw("The file does not exists.", TempScreen1); } } Console.Clear (); CodeScreen screen = new CodeScreen (mainPath, "SHELL"); Stopwatch renderTime = new Stopwatch (); renderTime.Start (); try { MasterEvaluator.Evaluate (code, screen); //Console .Beep (); } catch { Reporter.Throw("Something bad happend...", screen); //McError.Throw(ex.Data.ToString () + ": " + ex.Message); goto Start; } renderTime.Stop (); IDEInterface.TheA6 (renderTime.Elapsed.ToString()); goto Start; }
public static void Main(string[] args) { if (args.Length == 1) { // // Some UNIX style command line codes // if (args [0] == "-v" || args [0] == "--version") { InterfaceView.CommandLineVersion (); } else if (args [0] == "-h" || args [0] == "--help") { InterfaceView.CommnadLineHelp (); // // Or opening a file // } else { ArcadeLoading.Loading (1); Interface.OpenFileMain (args [0]); } } else if (args.Length == 2 || args.Length >= 3 && args [0] == "-e" || args.Length >= 3 && args [0] == "--evaluate") { if (args.Length == 2) { ArcadeLoading.Loading (1); EvaluatedMain (args [1], "SHELL"); } else { if (Directory.Exists (args [2])) { ArcadeLoading.Loading (1); EvaluatedMain (args [1], args [2]); } else { CodeScreen tempScreen4 = new CodeScreen ("SHELL", "SHELL"); tempScreen4.OpenedByArgs = true; Reporter.Throw ("MainPath refrences in command line does not exists.", tempScreen4); } } } else { ArcadeLoading.Loading (0); Interface.RealMain (); } }
/// <summary> /// Evaluates Arendelle Functions /// </summary> /// <param name='arendelle'> /// Arendelle. /// </param> /// <param name='screen'> /// Screen. /// </param> /// <param name='Spaces'> /// Spaces. /// </param> /// <param name='WhileSign'> /// While sign. /// </param> public static string EVAL(ref Arendelle arendelle, ref CodeScreen screen, ref DataTable spaces, ref bool whileSign) { // FunctionParser is a lexer like thing that return a list <string> // that the first part 'FunctionParts[0]' will be the Function's name // and the rest is function spaces in it's () var functionParts = FunctionParser.Parser (ref arendelle, screen); string functionName = functionParts [0]; if (functionName != "BadFuncName"){ // Functions name with screen.MainPath creates a path where the func is in // and this Path.PathGenerator which takes care of that. Also you must keep // in mind that we have used os specific codes for both UNIX and Windows // architectures so the final code is cross-platfrom with no need for any // change in their codes. string functionPath = Paths.PathGenerator (functionName, "arendelle", screen); // Setting up the Kernel.EVAL requirments CodeScreen funcScreen = new CodeScreen (screen.MainPath, functionName); funcScreen.OpenedByArgs = screen.OpenedByArgs; Arendelle funcCode; if (File.Exists (functionPath)) { funcCode = new Arendelle (MasterEvaluator.CommentRemover (ArendelleFile.read(functionPath, screen), funcScreen)); bool ws2 = true; List<string> spaceNames = new List<string> { }; // This while is a lexer that breacks down the function header to // a list<string> called 'SpacesNames' while ( ws2 ) { string command = funcCode.code[funcCode.i].ToString (); if (command == "<") { spaceNames = Lexers.OpenCloseLexer ("<", ref funcCode, ref funcScreen); funcCode.i ++; ws2 = false; } else { if (command == " " || command == "\n" || command == "\t") { funcCode.i ++; if ( funcCode.i > funcCode.code.Length ) ws2 = false; if ( command == "\n" ) funcScreen.line ++; } else { ws2 = false; } } } // So we have to be sure if the user has entered the function spaces right // for example if the header be '< @size , @age >' user must write a function // with only two numbers like : '$ example ( @size , 20 )' not '$ example (1)' // and not '$ example ( 10 , 20 , 31 )'. This if takes care of that if (functionParts.Count - 1 == spaceNames.Count) { // setting up the data DataTable funcSpaces = new DataTable ("spaces"); funcSpaces.Columns.Add ("name"); funcSpaces.Columns.Add ("space"); // As you know to return something in Arendelle functions // we fill them into @return space. The Kernel.EVAL removes // spaces that has made in it so no space from a grammar // inside another grammar wont interface with the mother // grammar and also the @return has one defualt space which // is zero so we add the @return here to fix those problems funcSpaces.Rows.Add ("@return", "0"); // In this part we group each FunctionSpaceName with it's own // FunctionSpaceSpace and we add them into Function's Space for (int i = 0; i < spaceNames.Count; i++) { string spaceName = spaceNames [ i ].TrimEnd().TrimStart(); Space.CheckSpaceName (spaceName, ref screen); if (spaceName.Replace (" ","" ) != "") { if (functionParts [ i + 1 ].Replace (" ","") != "") { string FuncTempSpace = Space.Calculate (functionParts[i+1], ref spaces, screen); funcSpaces.Rows.Add ("@"+spaceName, FuncTempSpace); } else { Reporter.Throw("Unsigned function space: "+spaceName, screen); } } } // Function should get the previus information about // the screen and use it and after it's job is finished // update it's mother screen funcScreen.x = screen.x ; funcScreen.y = screen.y ; funcScreen.z = screen.z ; funcScreen.color = screen.color ; funcScreen.rand = screen.rand ; Kernel.Eval (ref funcCode, ref funcScreen, ref funcSpaces, ref whileSign); screen.x = funcScreen.x ; screen.y = funcScreen.y ; screen.z = funcScreen.z ; screen.color = funcScreen.color ; screen.rand = funcScreen.rand ; // When we use functions as spaces we have to return // the last space-value of @return DataRow[] rows = funcSpaces.Select("name = '@return'"); return rows[0][1].ToString(); } else { string throwText = ""; switch (spaceNames.Count) { case 0 : throwText = "no space."; break; case 1 : throwText = "one space."; break; default: throwText = spaceNames.Count+" spaces."; break; } Reporter.Throw ("Function '"+functionName+"' takes "+throwText, screen); return "0"; } } else { Reporter.Throw ("Undifined function: '"+functionName+"'", screen); } return "0"; } return "0"; }
/// <summary> /// Eval is the main core of the language where it evaluates the given code. /// </summary> /// <param name='Code'> /// a given code like "rrc [ 8 , d [ 4 , r c n ] ] " /// </param> /// <param name='i'> /// the 'i' is the current pasring character /// </param> /// <param name='X'> /// X.the vector location. /// </param> /// <param name='Y'> /// Y. the vector location /// </param> /// <param name='Color'> /// Color. the number of color based on interface settings. /// </param> public static List<string> Eval(ref Arendelle arendelle, ref CodeScreen screen, ref DataTable spaces, ref bool WhileSign) { List <string> spacesToRemove = new List<string> { }; // // So what we do is we read the code char-by-char and run the commands // Just-In-Time. if we find a grammar we let grammar parsers take care // of that // while (arendelle.i < arendelle.code.Length) { // // To make our job easier we put the the char in a string // value so we can use it in a lazy way! // string command = arendelle.code [arendelle.i].ToString ().ToLower(); //////////////////////// /// START OF RUNTIME /// //////////////////////// switch (command) { //////////////////////////////////////////////////////////// // Grammars // //////////////////////////////////////////////////////////// case "[": Loop.LoopParser (ref arendelle, ref screen, ref spaces); //arendelle .i --; break; case "!": if (screen.MainPath != "SHELL") { FunctionEVAL.EVAL (ref arendelle, ref screen, ref spaces, ref WhileSign); } else { Reporter.Throw ("You can not use functions in interactive shell.",screen); } break; case "(": List <string> ValueGrammar = Lexers.OpenCloseLexer ("(", ref arendelle, ref screen); string r = Space.eval (ValueGrammar, ref spaces, screen); if (r != "") spacesToRemove.Add (r); break; case "{": List<string> conditionGrammar = Lexers.OpenCloseLexer ("{", ref arendelle, ref screen); Condition.Eval (conditionGrammar, ref screen, ref spaces); break; case "'": IDEInterface.SetMenuTitle (Lexers.OnePartOpenCloseParser ("'", ref arendelle, ref screen)); arendelle.i --; break; /////////////////////////////////////////////////////////////// // Commands // /////////////////////////////////////////////////////////////// case "p": IDEInterface.Paint (screen); break; case "u": screen.y --; break; case "d": screen.y ++; break; case "r": screen.x ++; break; case "l": screen.x --; break; case "e": screen.WhileSign = false; WhileSign = false; break; case "n": screen.color = (screen.color + 1) % 4; break; case "c": IDEInterface.Clear (screen); break; case "w": IDEInterface.Wait (screen); break; case "s": IDEInterface.HandleCommand_s (); break; case "i": screen.x = 0; screen.y = 0; break; /////////////////////////////////////////////////////////////// // Errors and Others // /////////////////////////////////////////////////////////////// case "]": Reporter.Throw ("Unexpected loop ender ']' found.", screen); break; case ")": Reporter.Throw ("Unexpected space ender ')' found.", screen); break; case "}": Reporter.Throw ("Unexpected conditon ender '}' found.", screen); break; case "<": Reporter.Throw ("Unexpected function header found.", screen); break; case ">": Reporter.Throw ("Unexpected function header ender '>' found.", screen); break; case ",": Reporter.Throw ("Unexpected grammar divider ',' found.", screen); break; case "\n" : screen.line ++; break; default: if (command != " " && command != "\t" && command != "" && command != ";") Reporter.Throw ("Unaccpeted command: '" + command + "'", screen); break; } ////////////////////// /// END OF RUNTIME /// ////////////////////// // // Garbedge Collector // arendelle.i++; } Garbedge.collector (ref spaces, spacesToRemove); // // RETURNINGS // return spacesToRemove; }
public static void Throw(string errorText, CodeScreen screen) { InterfaceView.ShowErros (errorText, screen); }
/// <summary> /// Expressions Analyzer for codnditions and equations . it seprates texts with an @ /// </summary> /// <returns> /// A list of stirings. you have to take care of strings opeining with @ /// </returns> /// <param name='expression'> /// Expression. a string like "2*@x-2" /// </param> public static List<string> ExpressionAnalyzer (string expression, ref CodeScreen screen) { // // The list we keep results in it. // List <string> args = new List<string> { }; // List of legal variable chars List <string> chars = new List<string> { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p", "q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F", "G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V", "W","X","Y","Z","_","1","2","3","4","5","6","7","8","9","0" }; // Current char that is being parsed. int i = 0; // Temp arg collector string arg = ""; // Core processor while (i < expression.Length) { // reading one char per time string theChar = expression [i] .ToString (); // is it space / source? if (theChar == "@" || theChar == "#") { args.Add (arg); // space or source if (theChar == "@") arg = "@"; else arg = "#"; // setting to the next char i++; // lexing the rest of the name until // we find the end of it by reading // only the meaningfull characters bool whilecontorol = true ; while (i < expression.Length && whilecontorol) { theChar = expression [i] .ToString (); if (chars.Exists(element => element == theChar)){ arg = arg + theChar; if (i < expression.Length) i++; else whilecontorol = false; } else { args.Add (arg); arg = " "; whilecontorol = false; } } // adding the lexed part args.Add (arg); arg = ""; i--; } else if (theChar == "!") { args.Add (arg); Arendelle FuncArendelle = new Arendelle(expression); FuncArendelle.i = i; var FunctionParts = FunctionParser.Parser (ref FuncArendelle, screen); i = FuncArendelle.i; arg = "!" + FunctionParts [0] + "("; for (int j = 1; j < FunctionParts.Count; j++) { arg = arg + FunctionParts [j] + ","; } args.Add (Mermaid.Text.RemoveEnd (arg , ",") + ")"); arg = ""; } else if (theChar == "$") { args.Add (arg); arg = "$"; i++; bool whilecontorol = true ; while (i < expression.Length && whilecontorol) { theChar = expression [i].ToString (); if (chars.Exists(element => element == theChar) || theChar == ".") { arg = arg + theChar; if (i < expression.Length) i++; else whilecontorol = false; } else { args.Add (arg); arg = " "; whilecontorol = false; } } if (arg.EndsWith (".")) Reporter.Throw("Bad stored space name: '" + arg + "'", screen); // adding the lexed part args.Add (arg); arg = ""; i--; // is it the end of the whole story? } else if (theChar == null) { args.Add (arg); return args; // now we are sure what we have lexed is // not one space or source } else { // translating some characters arg = arg.Replace ( "×" , "*" ); arg = arg.Replace ( "÷" , "/" ); // Translating Arendelle And/Or to NCalc's language. arg = arg.Replace ( " or " , "||" ); arg = arg.Replace ( " and " , "&&" ); arg = arg + theChar; } i++; } args.Add (arg ); return args; }
/// <summary> /// EValuates spaces. /// </summary> /// <returns>The eval.</returns> /// <param name="codes">Codes.</param> /// <param name="Spaces">Spaces.</param> /// <param name="screen">Screen.</param> public static string SpaceEval(List<string> codes, ref DataTable spaces, CodeScreen screen) { string name = ""; string space = ""; // // Stabelizing the value name // CheckSpaceName (codes [0].TrimEnd ().TrimStart (), ref screen); name = "@" + codes [0].TrimEnd ().TrimStart (); // // If count be two it means the given input is in the program // itself like: // // (a,2) ------in c#-------> int a = 2; // if (codes.Count == 2) { codes [1] = codes [1].TrimStart ().TrimEnd (); if (codes [1].StartsWith ("\"")) { Arendelle askText = new Arendelle (codes [1]); string text = Lexers.OnePartOpenCloseParser ("\"", ref askText, ref screen); space = Space.Calculate (IDEInterface.AskNumber (text), ref spaces, screen); } else if (codes [1].StartsWith ("/") || codes [1].StartsWith ("*") || codes [1].StartsWith ("+") || codes [1].StartsWith ("-")) { space = Space.Calculate (name + codes [1], ref spaces, screen); } else if (codes [1] == "done") { DataRow[] endrows = spaces.Select ("name = '" + name + "'"); if (endrows.Length > 0) spaces.Rows.Remove (endrows [0]); DataRow[] endrows2 = spaces.Select ("name = ''"); if (endrows2.Length > 0) spaces.Rows.Remove (endrows2 [0]); } else { space = Space.Calculate (codes [1], ref spaces, screen); } // // But if the count be one it means that user must enter the // value manualy (I/O) which means something like this: // // (a) ------in c#-------> int a = int.Prase ( Console.ReadLine ); // // NOTE: TO GET THE ACTUAL CODE OF SCREEN INPUT YOU MUST VISIT AND // MODIFY THE: /Engine/Interface/Engine-Tools/InterfaceCommands.cs // } else if (codes.Count == 1) { string text = "Sign space '" + name + "' with a number:"; space = Space.Calculate (IDEInterface.AskNumber (text), ref spaces, screen); } DataRow[] rows = spaces.Select ("name = '" + name + "'"); string toBeReturened = ""; if (rows.Length == 0) { spaces.Rows.Add (name, space); toBeReturened = name; } else { spaces.Rows [spaces.Rows.IndexOf (rows [0])] [1] = space; } // // Due type-safe design we have to remove the vars inside of a grammar // out side of it. I means something like this: // // A C# Code: // // | int a = 1; // | if ( a = 1 ) { // | int b = 0; // | } // | Console.WriteLine(b); // // So if you run the code you'll see the compiler saying that you can // not use the b outside of that if. Just as this example we have to // take care of inner vars because we use virtual types. it means all the // values are saved in a DataTable not actual places in system memory and // it dosen't matter where they are we have to simulate that system by // removing them when one grammar ( in this case one eval ) is done. // and we do this by collecting the name of values created inside of each // eval so when the evals finished we'll be able to remove them via // // -> garbedge.collector. // return toBeReturened; }
/// <summary> /// This grammars are started and closed with diffrent parts like ( .... , .... ) and contains /// some diffrent parts that we seprate them using ','. /// </summary> /// <returns> /// A list containing the parts, sorted. /// </returns> /// <param name='OpenCommand'> /// Open command. /// </param> /// <param name='arendelle'> /// Arendelle /// </param> /// <param name='screen'> /// Screen. /// </param> public static List<string> OpenCloseLexer (string openCommand, ref Arendelle arendelle, ref CodeScreen screen) { string closeCommand = null; screen.line2 = screen.line; switch (openCommand) { case "{" : closeCommand = "}"; break; case "[" : closeCommand = "]"; break; case "(" : closeCommand = ")"; break; case "<" : closeCommand = ">"; break; default: Reporter.Throw ("[DEV] - In Lexer : No such OpenCommand as '" + openCommand + "' Is Defiend." , screen); break; } // // With 'i' we will keep the place of the character // we are parsing. // arendelle.i++; // // This function parses an open-close grammer like [] fo // example: [20,rc] and returns {"20","rc"} or {r=2,rc,dc} // and the returns the {"r=2","rc","dc"}. This collection is // Args. // List < string > args = new List < string > {}; // // We put the current char in the commnad to have a more pretty // code. so after this we use Command as the Code[i].ToString(); // string command = null; // // A little char that we keep our parsing command // string arg = null; // // This while will take care of whole scanning thing. What it does is reading // the code char by char and adding the values into the result collection. // while (arendelle.i < arendelle.code .Length) { // // Commnad is the char we're going to parse // command = arendelle.code [arendelle.i].ToString (); if (command == ",") { args.Add (arg); arg = null; } else if (command == "[" || command == "(" || command == "{") { string opencommand = command; string closecommand = ""; switch (opencommand) { case "{" : closecommand = "}"; break; case "[" : closecommand = "]"; break; case "(" : closecommand = ")"; break; case "<" : closecommand = ">"; break; default: break; } List <string> newCodeToParse = OpenCloseLexer (command , ref arendelle, ref screen); string newCode = null; switch (newCodeToParse.Count) { case 1 : newCode = newCodeToParse [0] ; break; case 2 : newCode = newCodeToParse [0] + "," + newCodeToParse [1]; break; case 3 : newCode = newCodeToParse [0] + "," + newCodeToParse [1] + "," + newCodeToParse [2]; break; default: break; } arg = arg + opencommand + newCode + closecommand; } else if (command == closeCommand) { args.Add (arg); arg = null; goto Finishing; } else { if (command == "\n") screen .line ++; arg = arg + command; } // // Going to the next char if it exists // if (arendelle.i < arendelle.code .Length) { arendelle.i ++; } else { args [0] = "BadGrammar"; goto Finishing; } } Finishing: // // We have used the 'ref' before the Int i, so we have // to use this line to fix errors of the // screen.line2 = 0; return args; }