コード例 #1
0
ファイル: Condition.cs プロジェクト: karyfoundation/arcade
		/// <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);

			}
		}
コード例 #2
0
        /// <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++;
                }
            }
        }
コード例 #3
0
        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;
        }
コード例 #4
0
ファイル: SpaceEval.cs プロジェクト: karyfoundation/arcade
        /// <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;
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
ファイル: Loop.cs プロジェクト: karyfoundation/arcade
		/// <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);

			}
		}
コード例 #7
0
        /// <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);

            }
        }
コード例 #8
0
		/// <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";
				
				}
			}
		}
コード例 #9
0
ファイル: EVAL.cs プロジェクト: karyfoundation/arcade
        /// <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;
        }
コード例 #10
0
		/// <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; 

		}
コード例 #11
0
ファイル: FunctionEVAL.cs プロジェクト: karyfoundation/arcade
        /// <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";
        }
コード例 #12
0
ファイル: Replacer.cs プロジェクト: karyfoundation/arcade
        /// <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;
        }
コード例 #13
0
        /// <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;

            }
        }
コード例 #14
0
		/// <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;
		}