Esempio n. 1
0
 /// <summary>
 /// This method runs main source file.
 /// </summary>
 private void runToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     //MessageBox.Show("IT'S RUNNING!");
     bStartBreaking = false;
     ShowRun();
     Func main = new Func(textBox1.Text);
     main.Run(this);
     frRun1.textBox2.Text += "\r\nPress ANY KEY...";
     bReadyToCloseRun = true;
     //HideRun();
 }
Esempio n. 2
0
 /// <summary>
 /// Method, processing simple sequence - A <+,-,*,/> B
 /// </summary>
 /// <param name="sParam">Sequence</param>
 /// <param name="fFunc">Func class instance</param>
 /// <returns>Result of the sequence.</returns>
 private string processSimpleSeq(string sParam, Func fFunc)
 {
     if (sParam.IndexOf('+') > -1)
     {
         string[] sSeqParams = sParam.Split('+');
         Base a = new Base();
         a.SetUntyped(sSeqParams[0].Trim());
         Base b = new Base();
         b.SetUntyped(sSeqParams[1].Trim());
         Base c = a + b;
         return c.Get();
     }
     else
         if (sParam.IndexOf('-') > -1)
         {
             string[] sSeqParams = sParam.Split('-');
             Base a = new Base();
             a.SetUntyped(sSeqParams[0].Trim());
             Base b = new Base();
             b.SetUntyped(sSeqParams[1].Trim());
             Base c = a - b;
             return c.Get();
         }
         else
             if (sParam.IndexOf('*') > -1)
             {
                 string[] sSeqParams = sParam.Split('*');
                 Base a = new Base();
                 a.SetUntyped(sSeqParams[0].Trim());
                 Base b = new Base();
                 b.SetUntyped(sSeqParams[1].Trim());
                 Base c = a * b;
                 return c.Get();
             }
             else
                 if (sParam.IndexOf('/') > -1)
                 {
                     string[] sSeqParams = sParam.Split('/');
                     Base a = new Base();
                     a.SetUntyped(sSeqParams[0].Trim());
                     Base b = new Base();
                     b.SetUntyped(sSeqParams[1].Trim());
                     Base c = a / b;
                     return c.Get();
                 }
                 else return sParam;
 }
Esempio n. 3
0
        /// <summary>
        /// This method executes one line of code.
        /// </summary>
        /// <param name="cmd">The name of command to execute.</param>
        /// <param name="param">Parameters for this command</param>
        /// <param name="fFunc">The instance of Func class, which is currently running.</param>
        /// <returns>String, which is the result of executing this cmd. </returns>
        public string execCmd(string cmd, string param, Func fFunc)
        {
            ///Here will be (switch), which will run functions for standart cmd signatures
            try
            {
                if (bStartBreaking) { return ""; }
                if ((cmd!="=")&&(cmd!="#in")) ///if we have cmd, that is not changing vars - then process them = change to thier values
                {
                    param=processVars(param,fFunc);
                }

                switch (cmd.ToLower())
                {
                    case "#outstream":
                        param = processVars(param, fFunc);
                        fFunc.sOutput = param.Trim();
                        return "";
                    case "#instream":
                        param = processVars(param, fFunc);
                        fFunc.sInput = param.Trim();
                        return "";
                    case "#temp": // this cmd is used only for testing some features, i.e. processing simple seq.
                        param = processSimpleSeq(param, fFunc);
                        frRun1.textBox2.Text += param;
                        frRun1.textBox2.Refresh();
                        return "";
                    case "#in":
                        string ret = "";
                        string varName = param.Split(' ')[0];
                        if (fFunc.sInput.ToLower() == "console")
                        {
                            ret = frRun1.gettext();
                        }
                        else
                        {
                            FileStream FS = new FileStream(fFunc.sInput, FileMode.OpenOrCreate);
                            StreamReader SR = new StreamReader(FS);
                            ret = SR.ReadToEnd();
                            SR.Close();
                            FS.Close();
                        }

                        if (varName.IndexOf('@') == 0) //local var
                        {
                            fFunc.setVar(new Base(varName, ret));
                        }
                        else
                            if (varName.IndexOf('&') == 0) //global var
                            {
                                fFunc.setGlVar(new Base(varName, ret));
                            }

                        return "";

                    case "=":
                        string var1Name = param.Split(' ')[0];
                        param = param.Substring(var1Name.Length + 1);
                        param = processVars(param, fFunc);
                        if (isCmd(param))
                        {
                            string[] sCmdPar = extractCmdParam(param);
                            param = sCmdPar[0] + execCmd(sCmdPar[1], sCmdPar[2], fFunc);
                        }

                        param = param.Trim();

                        if (param[0] == '(' && param[param.Length - 1] == ')')
                        {
                            param = processBlanks(param, fFunc);
                            param = processVars(param, fFunc);
                            param = processComplicatedSeq(param);
                        }
                        long lg;
                        double db;
                        Base b;
                        if (long.TryParse(param,out lg))
                            {
                                b = new Base(var1Name, lg);
                            }
                        else
                            if (double.TryParse(param, out db))
                            {
                                b = new Base(var1Name, db);
                            }
                            else
                            {
                                b = new Base(var1Name, param);
                            }

                            if (var1Name.IndexOf('@') == 0)
                        {
                            fFunc.setVar(b);
                        }
                        else
                            if (var1Name.IndexOf('&') == 0)
                            {
                                fFunc.setGlVar(b);
                            }

                        return "";

                    case "#function":
                        if (isCmd(param))
                        {
                            string[] sCmdPar = extractCmdParam(param);
                            param = sCmdPar[0] + execCmd(sCmdPar[1], sCmdPar[2],fFunc);
                        }
                        string funcPath = param.Split(' ')[0];
                        param = param.Substring(param.IndexOf(' ') + 1);
                        string fullPath="";

                        if (path.Trim() != "")
                        {
                            if (File.Exists(Path.GetDirectoryName(path) + "\\" + funcPath + ".ps"))
                            {
                                fullPath = Path.GetDirectoryName(path) + "\\" + funcPath + ".ps";
                            }
                        }
                        if (fullPath=="")
                            if (File.Exists(Path.GetDirectoryName(Application.ExecutablePath) + "\\" + funcPath + ".ps"))
                            {
                                fullPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\" + funcPath + ".ps";
                            }
                        if (fullPath!="")
                        {
                            FileStream FS = new FileStream(fullPath, FileMode.OpenOrCreate);

                            StreamReader SR = new StreamReader(FS);
                            string funcSource = SR.ReadToEnd();
                            SR.Close();
                            FS.Close();

                            Func fnAdditional = new Func(funcSource, param);
                            string sReturn = fnAdditional.Run(this);
                            return sReturn;
                        }
                        else
                            return "Error while launching function " + funcPath;
                    case "#random":///random a b
                        if (isCmd(param))
                        {
                            string[] sCmdPar = extractCmdParam(param);
                            param = sCmdPar[0] + execCmd(sCmdPar[1], sCmdPar[2], fFunc);
                        }
                        Random rnd = new Random(DateTime.Now.Millisecond);
                        string[] par = param.Split(' ');
                        string ans = rnd.Next(Int32.Parse(par[0]), Int32.Parse(par[1])).ToString();
                        param = param.Substring(par[0].Length + 1 + par[1].Length);
                        param.Trim();

                        return ans + param;

                    case "#out":
                        if (isCmd(param))
                        {
                            string[] sCmdPar = extractCmdParam(param);
                            param = sCmdPar[0] + execCmd(sCmdPar[1], sCmdPar[2],fFunc);
                        }
                        ///DELETE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                        if (param[0] == '(' && param[param.Length - 1] == ')')
                        {
                            param = processBlanks(param, fFunc);
                            param = processVars(param, fFunc);
                            param = processComplicatedSeq(param);
                        }
                        param = param.Replace("\\n", "\r\n");
                        param = param.Replace("==", "=");
                        if (fFunc.sOutput.ToLower() == "console")
                        {
                            frRun1.textBox2.Text += param;
                            frRun1.textBox2.Refresh();
                        }
                        else
                        {
                            FileStream FS = new FileStream(fFunc.sOutput.Trim(), FileMode.OpenOrCreate);
                            StreamWriter SW = new StreamWriter(FS);
                            SW.Write(param);
                            SW.Close();
                            FS.Close();
                        }
                        return "";

                    case "#time":

                        if (isCmd(param))
                        {
                            string[] sCmdPar = extractCmdParam(param);
                            param = sCmdPar[0] + execCmd(sCmdPar[1], sCmdPar[2], fFunc);
                        }
                        return DateTime.Now.TimeOfDay + " " + param;

                    case "#sleep":
                        System.Threading.Thread.Sleep(Int32.Parse(param));
                        return "";

                    case "#clear": // this command use for clear program - window
                        frRun1.textBox2.Clear();
                        return "";

                    case "#return":
                        if (isCmd(param))
                        {
                            string[] sCmdPar = extractCmdParam(param);
                            param = sCmdPar[0] + execCmd(sCmdPar[1], sCmdPar[2], fFunc);
                        }
                        return param;

                    default:
                        return execCmd("#function", cmd.Remove(0,1) + " " + param, fFunc);
                    //  return "Err";
                }
            }
            catch
            {
                return "Parse_Error! Unknown command!";
            }
        }
Esempio n. 4
0
 /// <summary>
 /// This method is processing vars.
 /// </summary>
 /// <param name="sParam">String with @vars.</param>
 /// <param name="fFunc">The instance of Func class, which is currently running.</param>
 /// <returns>String, where all @vars are changed to their values.</returns>
 public string processVars(string sParam, Func fFunc)
 {
     string sRet = "";
     string[] splitParam = sParam.Split(' ');
     foreach (string s in splitParam)
     {
         if (s.IndexOf('@') == 0) // if local var
         {
             sRet += fFunc.getVar(s) + " ";
         }
         else
             if (s.IndexOf('&') == 0) //if global var
             {
                 sRet += fFunc.getGlVar(s) + " ";
             }
             else sRet += s + " ";
     }
     sRet = sRet.Trim();
     return sRet;
 }
Esempio n. 5
0
        /// <summary>
        /// This method process some logical sequence and returns result - is it true or false.
        /// </summary>
        /// <param name="sParam">Some sequence</param>
        /// <param name="fFunc">Func class instance</param>
        /// <returns>Is this seq. true or false.</returns>
        public bool processLogicalSeq(string sParam, Func fFunc)
        {
            bool answer = false;

            string[] logicalMarks = new string[6] { "<=", ">=", "==", "!=", "<", ">"};
            string[] sParams = sParam.Split(logicalMarks, StringSplitOptions.None);
            if (sParams.Length != 1)
            {
                string usedLogic = sParam.Substring(sParams[0].Length, sParam.Length - sParams[0].Length - sParams[1].Length).Trim();
                sParams[0] = processComplicatedSeq(processVars(sParams[0].Trim(), fFunc));
                sParams[1] = processComplicatedSeq(processVars(sParams[1].Trim(), fFunc));
                if (!bStartBreaking)
                {
                    Base a = new Base();
                    a.SetUntyped(sParams[0]);
                    Base b = new Base();
                    b.SetUntyped(sParams[1]);

                    switch (usedLogic)
                    {
                        case "<":
                            answer = (a < b);
                            break;
                        case ">":
                            answer = (a > b);
                            break;
                        case "<=":
                            answer = (a <= b);
                            break;
                        case ">=":
                            answer = (a >= b);
                            break;
                        case "!=":
                            answer = (a != b);
                            break;
                        case "==":
                            answer = (a == b);
                            break;
                    }
                }
                else
                    switch (sParams[0][0])
                    {
                        case '@':
                            try
                            {
                                answer = Convert.ToBoolean(fFunc.getVar(sParams[0].Trim()));
                            }
                            catch
                            {
                                answer = false;
                            }
                            break;
                        case '&':
                            try
                            {
                                answer = Convert.ToBoolean(fFunc.getGlVar(sParams[0].Trim()));
                            }
                            catch
                            {
                                answer = false;
                            }
                            break;
                        default:
                            break;
                    }
            }
            return answer;
        }
Esempio n. 6
0
 public string processBlanks(string sParam, Func fFunc)
 {
     bool flag;
     char[] Marks = new char[] { '*', '/', '+', '-' /*, ' '*/ , '(', ')' };
     // now space button - is the now onlyist way to split string
     for (int i = sParam.Length - 1; i >= 0; i--)
     {
         flag = false;
         foreach (char cNow in Marks)
         {
             if (cNow == sParam[i])
                 flag = true;
         }
         if (flag)
         {
             sParam = sParam.Insert(i + 1, " ");
             sParam = sParam.Insert(i, " ");
         }
     }
     return sParam;
 }