Exemplo n.º 1
0
        protected override Parser.Result Evaluate(string data, ref int from)
        {
            // 1. Get the name of the variable.
            string varName = Utils.GetToken(data, ref from, Constants.NEXT_ARG_ARRAY);

            if (from >= data.Length)
            {
                throw new ArgumentException("Couldn't append variable");
            }

            // 2. Get the current value of the variable.
            ParserFunction func = ParserFunction.GetFunction(varName);

            Parser.Result currentValue = func.GetValue(data, ref from);

            // 3. Get the value to be added or appended.
            Parser.Result newValue = Utils.GetItem(data, ref from);

            // 4. Take either the string part if it is defined,
            // or the numerical part converted to a string otherwise.
            string arg1 = currentValue.String != null ? currentValue.String :
                          currentValue.Value.ToString();
            string arg2 = newValue.String != null ? newValue.String :
                          newValue.Value.ToString();

            // 5. The variable becomes a string after adding a string to it.
            newValue.Reset();
            newValue.String = arg1 + arg2;

            ParserFunction.AddFunction(varName, new GetVarFunction(newValue));

            return(newValue);
        }
Exemplo n.º 2
0
        protected override Parser.Result Evaluate(string data, ref int from)
        {
            string varName = Utils.GetToken(data, ref from, Constants.NEXT_ARG_ARRAY);

            if (from >= data.Length)
            {
                throw new ArgumentException("Couldn't set variable before end of line");
            }

            Parser.Result varValue = Utils.GetItem(data, ref from);

            // Check if the variable to be set has the form of x(0),
            // meaning that this is an array element.
            int arrayIndex = Utils.ExtractArrayElement(ref varName);

            if (arrayIndex >= 0)
            {
                bool          exists       = ParserFunction.FunctionExists(varName);
                Parser.Result currentValue = exists ?
                                             ParserFunction.GetFunction(varName).GetValue(data, ref from) :
                                             new Parser.Result();

                List <Parser.Result> tuple = currentValue.Tuple == null ?
                                             new List <Parser.Result>() :
                                             currentValue.Tuple;
                if (tuple.Count > arrayIndex)
                {
                    tuple[arrayIndex] = varValue;
                }
                else
                {
                    for (int i = tuple.Count; i < arrayIndex; i++)
                    {
                        tuple.Add(new Parser.Result(Double.NaN, string.Empty));
                    }
                    tuple.Add(varValue);
                }

                varValue = new Parser.Result(Double.NaN, null, tuple);
            }

            ParserFunction.AddFunction(varName, new GetVarFunction(varValue));

            return(new Parser.Result(Double.NaN, varName));
        }
Exemplo n.º 3
0
        public void AddTranslation(NameValueCollection languageDictionary, string originalName)
        {
            string translation = languageDictionary[originalName];

            if (string.IsNullOrWhiteSpace(translation))
            { // The translation is not provided for this function.
                return;
            }

            if (translation.IndexOfAny((" \t\r\n").ToCharArray()) >= 0)
            {
                throw new ArgumentException("Translation of [" + translation + "] contains white spaces");
            }

            ParserFunction originalFunction = ParserFunction.GetFunction(originalName);

            ParserFunction.AddFunction(translation, originalFunction);
        }
Exemplo n.º 4
0
        public bool ReLoad(string sfolderName = "")
        {
            try
            {
                //sScript = null;
                String FolderName;
                if (sfolderName == "")
                {
                    FolderName = System.AppDomain.CurrentDomain.BaseDirectory + "Script";
                }
                else
                {
                    FolderName = sfolderName;
                }
                s_Script.Clear();

                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(FolderName);
                foreach (System.IO.FileInfo file in di.GetFiles())
                {
                    if (file.Extension.ToLower().CompareTo(".cscs") == 0)
                    {
                        String   FileNameOnly = file.Name.Substring(0, file.Name.Length - 5);
                        string[] readText     = File.ReadAllLines(file.FullName);

                        string script = Utils.ConvertToScript(string.Join("\n", readText));
                        //if(FileNameOnly.ToLower() == "sequence") sScript = script;
                        //Parser parser = new Parser(script);
                        //parser.parserFunction.AddFunction("Cycle."+ FileNameOnly, new GetVarFunction(new Parser.Result(Double.NaN,FileNameOnly),Parser.Instance));
                        s_Script[FileNameOnly] = script;//new Parser(script);
                        ParserFunction.AddFunction(FileNameOnly, new GetVarFunction(new Parser.Result(0, null)));
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Log.ShowMessage("Script Load Fail ", ex.Message);
                return(false);
            }
        }
Exemplo n.º 5
0
        public void Init()
        {
            ParserFunction.AddFunction(Constants.IF, new IfStatement());
            ParserFunction.AddFunction(Constants.WHILE, new WhileStatement());
            ParserFunction.AddFunction(Constants.BREAK, new BreakStatement());
            ParserFunction.AddFunction(Constants.CONTINUE, new ContinueStatement());

            ParserFunction.AddFunction(Constants.ABS, new AbsFunction());
            ParserFunction.AddFunction(Constants.APPEND, new AppendFunction());
            ParserFunction.AddFunction(Constants.CD, new CdFunction());
            ParserFunction.AddFunction(Constants.CD__, new Cd__Function());
            ParserFunction.AddFunction(Constants.DIR, new DirFunction());
            ParserFunction.AddFunction(Constants.ENV, new GetEnvFunction());
            ParserFunction.AddFunction(Constants.EXP, new ExpFunction());
            ParserFunction.AddFunction(Constants.FINDFILES, new FindfilesFunction());
            ParserFunction.AddFunction(Constants.FINDSTR, new FindstrFunction());
            ParserFunction.AddFunction(Constants.INDEX_OF, new IndexOfFunction());
            ParserFunction.AddFunction(Constants.KILL, new KillFunction());
            ParserFunction.AddFunction(Constants.PI, new PiFunction());
            ParserFunction.AddFunction(Constants.POW, new PowFunction());
            ParserFunction.AddFunction(Constants.PRINT, new PrintFunction());
            ParserFunction.AddFunction(Constants.PSINFO, new PsInfoFunction());
            ParserFunction.AddFunction(Constants.PSTIME, new ProcessorTimeFunction());
            ParserFunction.AddFunction(Constants.PWD, new PwdFunction());
            ParserFunction.AddFunction(Constants.RUN, new RunFunction());
            ParserFunction.AddFunction(Constants.SET, new SetVarFunction());
            ParserFunction.AddFunction(Constants.SETENV, new SetEnvFunction());
            ParserFunction.AddFunction(Constants.SIN, new SinFunction());
            ParserFunction.AddFunction(Constants.SIZE, new SizeFunction());
            ParserFunction.AddFunction(Constants.SQRT, new SqrtFunction());
            ParserFunction.AddFunction(Constants.SUBSTR, new SubstrFunction());
            ParserFunction.AddFunction(Constants.TOLOWER, new ToLowerFunction());
            ParserFunction.AddFunction(Constants.TOUPPER, new ToUpperFunction());

            ELSE_LIST.Add(Constants.ELSE);
            ELSE_IF_LIST.Add(Constants.ELSE_IF);

            ReadConfig();
        }
Exemplo n.º 6
0
        public void Init()
        {
            ParserFunction.AddFunction(Constants.IF, new IfStatement());
            ParserFunction.AddFunction(Constants.WHILE, new WhileStatement());
            ParserFunction.AddFunction(Constants.BREAK, new BreakStatement());
            ParserFunction.AddFunction(Constants.CONTINUE, new ContinueStatement());

            ParserFunction.AddFunction(Constants.ABS, new AbsFunction());
            ParserFunction.AddFunction(Constants.APPEND, new AppendFunction());
            ParserFunction.AddFunction(Constants.CD, new CdFunction());
            ParserFunction.AddFunction(Constants.CD__, new Cd__Function());
            ParserFunction.AddFunction(Constants.DIR, new DirFunction());
            ParserFunction.AddFunction(Constants.ENV, new GetEnvFunction());
            ParserFunction.AddFunction(Constants.EXP, new ExpFunction());
            ParserFunction.AddFunction(Constants.FINDFILES, new FindfilesFunction());
            ParserFunction.AddFunction(Constants.FINDSTR, new FindstrFunction());
            ParserFunction.AddFunction(Constants.INDEX_OF, new IndexOfFunction());
            ParserFunction.AddFunction(Constants.KILL, new KillFunction());
            ParserFunction.AddFunction(Constants.PI, new PiFunction());
            ParserFunction.AddFunction(Constants.POW, new PowFunction());
            ParserFunction.AddFunction(Constants.PRINT, new PrintFunction());
            ParserFunction.AddFunction(Constants.PSINFO, new PsInfoFunction());
            ParserFunction.AddFunction(Constants.PSTIME, new ProcessorTimeFunction());
            ParserFunction.AddFunction(Constants.PWD, new PwdFunction());
            ParserFunction.AddFunction(Constants.RUN, new RunFunction());
            ParserFunction.AddFunction(Constants.SET, new SetVarFunction());
            ParserFunction.AddFunction(Constants.SETENV, new SetEnvFunction());
            ParserFunction.AddFunction(Constants.SIN, new SinFunction());
            ParserFunction.AddFunction(Constants.SIZE, new SizeFunction());
            ParserFunction.AddFunction(Constants.SQRT, new SqrtFunction());
            ParserFunction.AddFunction(Constants.SUBSTR, new SubstrFunction());
            ParserFunction.AddFunction(Constants.TOLOWER, new ToLowerFunction());
            ParserFunction.AddFunction(Constants.TOUPPER, new ToUpperFunction());

            ELSE_LIST.Add(Constants.ELSE);
            ELSE_IF_LIST.Add(Constants.ELSE_IF);



            ParserFunction.AddFunction(Constants.TRUE, new True());
            ParserFunction.AddFunction(Constants.FALSE, new False());

            ParserFunction.AddFunction(Constants.MOTOR_MOVE, new Motor_Move());
            ParserFunction.AddFunction(Constants.MOTOR_MOVEPOS, new Motor_MovePos());
            ParserFunction.AddFunction(Constants.MOTOR_CHECKSTOP, new Motor_CheckStop());
            ParserFunction.AddFunction(Constants.MOTOR_CHECKSTOPPOS, new Motor_CheckStopPos());
            ParserFunction.AddFunction(Constants.MOTOR_STOP, new Motor_Stop());
            ParserFunction.AddFunction(Constants.MOTOR_SERVO, new Motor_Servo());
            ParserFunction.AddFunction(Constants.MOTOR_HOME, new Motor_Home());
            ParserFunction.AddFunction(Constants.MOTOR_CHECKHOME, new Motor_CheckHome());

            ParserFunction.AddFunction(Constants.CYLINDER_MOVE, new Cylinder_Move());
            ParserFunction.AddFunction(Constants.CYLINDER_CHECKSTOP, new Cylinder_CheckStop());

            ParserFunction.AddFunction(Constants.IO_SETY, new IO_SetY());
            ParserFunction.AddFunction(Constants.IO_GETX, new IO_GetX());

            ParserFunction.AddFunction(Constants.RETURN, new Return());
            ParserFunction.AddFunction(Constants.END, new End());
            ParserFunction.AddFunction(Constants.STOPWATCH, new StopWatch());

            ParserFunction.AddFunction(Constants.DATA_SET, new Data_Set());
            ParserFunction.AddFunction(Constants.DATA_GET, new Data_Get());

            ParserFunction.AddFunction(Constants.ERROR_SET, new Error_Set());

            ParserFunction.AddFunction(Constants.POSITION_GET, new Position_Get());

            ParserFunction.AddFunction(Constants.OPTION_DEVICE, new Option_Device());
            ParserFunction.AddFunction(Constants.OPTION_COMMON, new Option_Common());

            //Enum
            var sList = new List <Tuple <string, int> >();

            //sList = Utils.GetList(typeof(fb)); foreach(var slist in sList) ParserFunction.AddFunction("fb."+slist.Item1, new GetVarFunction(new Parser.Result(sList.IndexOf(slist))));
            sList = Utils.GetList(typeof(fb)); foreach (var slist in sList)
            {
                ParserFunction.AddFunction("fb." + slist.Item1, new GetVarFunction(new Parser.Result(slist.Item2)));
            }
            sList = Utils.GetList(typeof(mi)); foreach (var slist in sList)
            {
                ParserFunction.AddFunction("mi." + slist.Item1, new GetVarFunction(new Parser.Result(slist.Item2)));
            }
            sList = Utils.GetList(typeof(ci)); foreach (var slist in sList)
            {
                ParserFunction.AddFunction("ci." + slist.Item1, new GetVarFunction(new Parser.Result(slist.Item2)));
            }
            sList = Utils.GetList(typeof(xi)); foreach (var slist in sList)
            {
                ParserFunction.AddFunction("xi." + slist.Item1, new GetVarFunction(new Parser.Result(slist.Item2)));
            }
            sList = Utils.GetList(typeof(yi)); foreach (var slist in sList)
            {
                ParserFunction.AddFunction("yi." + slist.Item1, new GetVarFunction(new Parser.Result(slist.Item2)));
            }
            sList = Utils.GetList(typeof(ei)); foreach (var slist in sList)
            {
                ParserFunction.AddFunction("ei." + slist.Item1, new GetVarFunction(new Parser.Result(slist.Item2)));
            }
            sList = Utils.GetList(typeof(cs)); foreach (var slist in sList)
            {
                ParserFunction.AddFunction("cs." + slist.Item1, new GetVarFunction(new Parser.Result(slist.Item2)));
            }
            sList = Utils.GetList(typeof(ri)); foreach (var slist in sList)
            {
                ParserFunction.AddFunction("ri." + slist.Item1, new GetVarFunction(new Parser.Result(slist.Item2)));
            }
            sList = Utils.GetList(typeof(pv)); foreach (var slist in sList)
            {
                ParserFunction.AddFunction("pv." + slist.Item1, new GetVarFunction(new Parser.Result(slist.Item2)));
            }

            //StopWatch
            ParserFunction.AddFunction("sw.Start", new GetVarFunction(new Parser.Result(0)));
            ParserFunction.AddFunction("sw.Stop", new GetVarFunction(new Parser.Result(1)));
            ParserFunction.AddFunction("sw.Restart", new GetVarFunction(new Parser.Result(2)));
            ParserFunction.AddFunction("sw.ms", new GetVarFunction(new Parser.Result(3)));

            //Sequence step
            ParserFunction.AddFunction("seq.Step", new GetVarFunction(new Parser.Result(0)));
            ParserFunction.AddFunction("seq.Run", new GetVarFunction(new Parser.Result((double)SML.EN_SEQ_STEP.Run)));
            ParserFunction.AddFunction("seq.ToStop", new GetVarFunction(new Parser.Result((double)SML.EN_SEQ_STEP.ToStop)));
            ParserFunction.AddFunction("seq.ToStart", new GetVarFunction(new Parser.Result((double)SML.EN_SEQ_STEP.ToStart)));

            ReadConfig();
            ReLoad();
        }