示例#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);
        }
示例#2
0
        protected override Parser.Result Evaluate(string data, ref int from)
        {
            string varName = Utils.GetToken(data, ref from, Constants.END_ARG_ARRAY);

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

            Parser.Result varValue = new Parser.Result();
            string        value    = ScDumper.GetValue(nv);

            varValue.Value = Double.Parse(value);
            // 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 ?? new List <Parser.Result>();
                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));
        }
示例#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);
        }
示例#4
0
        public void Init()
        {
            ParserFunction.AddFunction(Constants.IF, new IfStatement(this));
            ParserFunction.AddFunction(Constants.WHILE, new WhileStatement(this));
            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(this));
            ParserFunction.AddFunction(Constants.ENV, new GetEnvFunction());
            ParserFunction.AddFunction(Constants.EXP, new ExpFunction());
            ParserFunction.AddFunction(Constants.FINDFILES, new FindfilesFunction(this));
            ParserFunction.AddFunction(Constants.FINDSTR, new FindstrFunction(this));
            ParserFunction.AddFunction(Constants.INDEX_OF, new IndexOfFunction());
            ParserFunction.AddFunction(Constants.KILL, new KillFunction(this));
            ParserFunction.AddFunction(Constants.PI, new PiFunction());
            ParserFunction.AddFunction(Constants.POW, new PowFunction());
            ParserFunction.AddFunction(Constants.PRINT, new PrintFunction(this));
            ParserFunction.AddFunction(Constants.PSINFO, new PsInfoFunction(this));
            ParserFunction.AddFunction(Constants.PSTIME, new ProcessorTimeFunction());
            ParserFunction.AddFunction(Constants.PWD, new PwdFunction(this));
            ParserFunction.AddFunction(Constants.RUN, new RunFunction(this));
            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();
        }