예제 #1
0
        public bool TryInterpret(CodeInterpreter compiler, CodeReader reader, out IProcess process)
        {
            process = null;

            var backup = reader.Backup();

            if (reader.ReadName(out var name))
            {
                process = new GetFieldProcess(name);

                return(true);
            }

            backup.Restore();

            return(false);
        }
예제 #2
0
        public bool TryInterpret(CodeInterpreter compiler, CodeReader reader, out IProcess process)
        {
            var backup = reader.Backup();

            if (reader.ReadChar(out var bracketBegin) && bracketBegin == '(')
            {
                process = compiler.Interpret(reader, Priorities.None);

                if (reader.ReadChar(out var bracketEnd) && bracketEnd == ')')
                {
                    return(true);
                }
            }

            process = null;

            backup.Restore();

            return(false);
        }
예제 #3
0
        public bool TryInterpret(CodeInterpreter compiler, CodeReader reader, out IProcess process)
        {
            var backup = reader.Backup();

            process = null;

            if (reader.ReadName(out var name) && reader.ReadChar(out var bracketBegin) && bracketBegin == '(')
            {
                var parameters = new List <IProcess>();

Loop:

                if (reader.CurrentChar(out var bracketEnd) && bracketEnd == ')')
                {
                    reader.Next();

                    process = new InvokeFunctionProcess(name, parameters.ToArray());

                    return(true);
                }
예제 #4
0
        public bool TryInterpret(CodeInterpreter compiler, CodeReader reader, out IProcess process)
        {
            var backup = reader.Backup();

            process = null;

            if (reader.ReadName(out var _var) && _var == "var")
            {
Loop:

                if (reader.ReadName(out var name))
                {
                    IProcess initValue = null;

                    if (reader.CurrentChar(out var c) && c == '=')
                    {
                        reader.Next();

                        initValue = compiler.Interpret(reader, Priorities.AssignValueOperator);
                    }

                    if (reader.CurrentChar(out var c1) && c1 == ',')
                    {
                        reader.Next();

                        process = new VarProcess(name, initValue, process);

                        goto Loop;
                    }

                    process = new VarProcess(name, initValue, process);

                    return(true);
                }
            }

            backup.Restore();

            return(false);
        }
예제 #5
0
        public bool TryInterpret(CodeInterpreter compiler, CodeReader reader, out IProcess process)
        {
            var backup = reader.Backup();

            process = null;

            if (compiler.TryInterpret(reader, Priority, out var before))
            {
                if (reader.ReadOperator(out var operatorText) && OperatorText == operatorText)
                {
                    if (compiler.TryInterpret(reader, Priority, out var after))
                    {
                        process = CreateProcess(before, after);

                        return(true);
                    }
                }
            }

            backup.Restore();

            return(false);
        }
예제 #6
0
        public unsafe bool TryInterpret(CodeInterpreter compiler, CodeReader reader, out IProcess process)
        {
            var backup = reader.Backup();

            process = null;

            if (reader.ReadNumber(out var text))
            {
                fixed(char *pText = text)
                {
                    var numberInfo = NumberHelper.GetNumberInfo(pText, text.Length, 10);

                    if (numberInfo.IsNumber)
                    {
                        if (numberInfo.HaveExponent)
                        {
                            process = new ConstantProcess(new DoubleConstant(numberInfo.ToDouble()));
                        }
                        else if (numberInfo.IsFloat)
                        {
                            if (numberInfo.IsDecimal && numberInfo.IntegerCount + numberInfo.FractionalCount <= 28)
                            {
                                process = new ConstantProcess(new DecimalConstant(numberInfo.ToDecimal()));
                            }
                            else
                            {
                                process = new ConstantProcess(new DoubleConstant(numberInfo.ToDouble()));
                            }
                        }
                        else if (numberInfo.IntegerCount <= 18)
                        {
                            process = new ConstantProcess(new Int64Constant(numberInfo.ToInt64()));
                        }
                        else if (numberInfo.IsDecimal && numberInfo.IntegerCount <= 28)
                        {
                            process = new ConstantProcess(new DecimalConstant(numberInfo.ToDecimal()));
                        }
                        else
                        {
                            process = new ConstantProcess(new DoubleConstant(numberInfo.ToDouble()));
                        }

                        return(true);
                    }
                }

                if (long.TryParse(text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out var int64Value))
                {
                    process = new ConstantProcess(new Int64Constant(int64Value));

                    return(true);
                }

                if (decimal.TryParse(text, NumberStyles.Float, NumberFormatInfo.CurrentInfo, out var decimalValue))
                {
                    process = new ConstantProcess(new DecimalConstant(decimalValue));

                    return(true);
                }

                if (double.TryParse(text, NumberStyles.Float, NumberFormatInfo.CurrentInfo, out var doubleValue))
                {
                    process = new ConstantProcess(new DoubleConstant(doubleValue));

                    return(true);
                }
            }

            backup.Restore();

            return(false);
        }