예제 #1
0
 public BoundBinaryOperator(BinaryOperatorKind kind, DustType leftType, DustType rightType, DustType returnType, bool isInterchangeable = true)
 {
     Kind              = kind;
     LeftType          = leftType;
     RightType         = rightType;
     ReturnType        = returnType;
     IsInterchangeable = isInterchangeable;
 }
예제 #2
0
 public Function(string name, FunctionModifier[] modifiers, FunctionParameter[] parameters, Statement[] statements, DustType returnType, DustContext context, Range range)
     : base(range)
 {
     Name       = name;
     Parameters = parameters;
     Modifiers  = modifiers;
     Statements = statements;
     ReturnType = returnType;
     Context    = context;
 }
예제 #3
0
        public override Node VisitFunctionDeclaration(DustParser.FunctionDeclarationContext context)
        {
            string name = context.functionDeclarationBase().functionName().identifierName().GetText();

            FunctionModifier[]  modifiers  = context.functionDeclarationBase().functionModifier().Select(modifierContext => FunctionModifier.Parse(modifierContext.GetText())).ToArray();
            FunctionParameter[] parameters = context.functionParameterList()?.functionParameter().Select(Visit).Cast <FunctionParameter>().ToArray();

            if (visitorContext.ContainsPropety(name))
            {
                visitorContext.ErrorHandler.ThrowError(new SyntaxError($"Identifier '{name}' is already defined", context.functionDeclarationBase().functionName().GetRange()));

                return(null);
            }

            for (int i = 0; i < parameters?.Length; i++)
            {
                if (visitorContext.ContainsPropety(parameters[i].Identifier.Name))
                {
                    visitorContext.ErrorHandler.ThrowError(new SyntaxError($"Identifier '{name}' is already defined", context.functionParameterList().functionParameter(i).GetRange()));

                    return(null);
                }
            }

            DustVisitor      child      = CreateChild(parameters ?? new FunctionParameter[0]);
            List <Statement> statements = new List <Statement>();

            DustType returnType = null;

            if (context.statementBlock() != null)
            {
                foreach (DustParser.StatementContext statementContext in context.statementBlock().statement())
                {
                    Statement statement = (Statement)child.Visit(statementContext);

                    if (statement is ReturnStatement)
                    {
                        // TODO: Fix the temporary HACK by creating a Type System.
                        returnType = DustType.Number;
                    }

                    statements.Add(statement);
                }
            }

            FunctionDeclaration declaration = new FunctionDeclaration(name, modifiers, parameters ?? new FunctionParameter[0], statements.ToArray(), returnType, child.visitorContext, new Range
            {
                Start = context.GetRange().Start,
                End   = context.functionDeclarationBase().functionName().GetRange().End
            });

            visitorContext.AddFunction(declaration.Function);

            return(declaration);
        }
예제 #4
0
    private GameObject _GetDustInstance(DustType rType) //根据灰尘的种类获取对应的灰尘预制体
    {
        switch (rType)
        {
        case DustType.WalkDust:
            int index = Random.Range(0, 3);
            return(Instantiate(_dustPrefabList[index]));

        case DustType.DashDust:
            return(Instantiate(_dashDustPrefab));

        case DustType.GroundDust:
            return(Instantiate(_groundDustPrefab));
        }

        return(null);
    }
예제 #5
0
        protected override string ObjectToString(DustType type, string target, string format)
        {
            switch (type)
            {
            case DustType.Undefined:
                break;

            case DustType.Sql:
                break;

            case DustType.Object:
                break;

            case DustType.Number:
                if (format == null)
                {
                    return(string.Concat("TO_CHAR(", target, ")"));
                }
                return(string.Concat("TO_CHAR(", target, ",", format, ")"));

            case DustType.Array:
                break;

            case DustType.Boolean:
                break;

            case DustType.DateTime:
                if (format == null)
                {
                    return(string.Concat("TO_CHAR(", target, ",'yyyy-mm-dd HH:mi:ss')"));
                }
                format = format.Replace("m", "mi").Replace("mimi", "mi");
                return(string.Concat("TO_CHAR(", target, ",", format, ")"));

            case DustType.Binary:
                break;

            case DustType.String:
                break;

            default:
                break;
            }
            return(base.ObjectToString(type, target, format));
        }
예제 #6
0
파일: SawDust.cs 프로젝트: blqw/blqw-Faller
 /// <summary> 初始化解析结果
 /// </summary>
 /// <param name="faller">解析组件</param>
 /// <param name="type">结果类型</param>
 /// <param name="value">结果值</param>
 internal SawDust(Faller faller, DustType type, Object value)
     : this()
 {
     if (type == DustType.Object && value is SawDust)
     {
         var dust = (SawDust)value;
         Value = dust.Value;
         Type  = dust.Type;
     }
     else
     {
         Type  = type;
         Value = value;
     }
     Faller   = faller;
     _toSqled = false;
     _sql     = null;
 }
예제 #7
0
 /// <summary> 初始化解析结果
 /// </summary>
 /// <param name="faller">解析组件</param>
 /// <param name="type">结果类型</param>
 /// <param name="value">结果值</param>
 internal SawDust(Faller faller, DustType type, Object value)
     : this()
 {
     if (type == DustType.Object && value is SawDust)
     {
         var dust = (SawDust)value;
         Value = dust.Value;
         Type = dust.Type;
     }
     else
     {
         Type = type;
         Value = value;
     }
     Faller = faller;
     _toSqled = false;
     _sql = null;
 }
예제 #8
0
        public static BoundBinaryOperator Bind(DustType leftType, BinaryOperatorKind kind, DustType rightType)
        {
            foreach (BoundBinaryOperator @operator in binaryOperators)
            {
                if (@operator.Kind == kind)
                {
                    if (@operator.LeftType.IsAssignableFrom(leftType) && @operator.RightType.IsAssignableFrom(rightType))
                    {
                        return(@operator);
                    }

                    if (@operator.IsInterchangeable && @operator.LeftType.IsAssignableFrom(rightType) && @operator.RightType.IsAssignableFrom(leftType))
                    {
                        return(@operator);
                    }
                }
            }

            return(null);
        }
예제 #9
0
        protected override object CompileUnaryExpression(UnaryExpression expression)
        {
            object            value     = CompileExpression(expression.Expression);
            UnaryOperatorType @operator = expression.Operator;

            if (expression.Expression is IdentifierExpression identifierExpression)
            {
                if (CompilerContext.ContainsPropety(identifierExpression.Name) == false)
                {
                    CompilerContext.ErrorHandler.ThrowError(new SyntaxError($"Identifier '{identifierExpression.Name}' is not defined", null));

                    return(null);
                }

                CompilerContext.DeleteProperty(identifierExpression);

                return(null);
            }

            if (expression.Expression is Function function)
            {
                if (CompilerContext.ContainsFunction(function.Name) == false)
                {
                    CompilerContext.ErrorHandler.ThrowError(new SyntaxError($"Function '{function.Name}' is not defined", null));

                    return(null);
                }

                CompilerContext.DeleteFunction(function);

                return(null);
            }

            if (DustType.GetDustType(value) == DustType.Number)
            {
                switch (@operator)
                {
                case UnaryOperatorType.PLUS_PLUS:
                    if (DustType.GetDustType(value) == DustType.Int)
                    {
                        return((int)value + 1);
                    }

                    return(Convert.ToSingle(value) + 1);

                case UnaryOperatorType.MINUS_MINUS:
                    if (DustType.GetDustType(value) == DustType.Int)
                    {
                        return((int)value - 1);
                    }

                    return(Convert.ToSingle(value) - 1);

                case UnaryOperatorType.TIMES_TIMES:
                    if (DustType.GetDustType(value) == DustType.Int)
                    {
                        return(Math.Pow((int)value, 2));
                    }

                    return(Math.Pow(Convert.ToSingle(value), 2));

                case UnaryOperatorType.DIVIDE_DIVIDE:
                    if (DustType.GetDustType(value) == DustType.Int)
                    {
                        return(Math.Sqrt((int)value));
                    }

                    return(Math.Sqrt(Convert.ToSingle(value)));
                }
            }

            if (DustType.GetDustType(value) == DustType.Bool)
            {
                switch (@operator)
                {
                case UnaryOperatorType.BANG:
                    if (DustType.GetDustType(value) == DustType.Bool)
                    {
                        return(!(bool)value);
                    }

                    break;
                }
            }

            return(null);
        }
예제 #10
0
        protected override object CompileBinaryExpression(BinaryExpression expression)
        {
            object             left      = CompileExpression(expression.Left);
            object             right     = CompileExpression(expression.Right);
            BinaryOperatorType @operator = expression.Operator;

            switch (@operator)
            {
            case BinaryOperatorType.EQUAL:
                return(left.Equals(right));

            case BinaryOperatorType.NOT_EQUAL:
                return(!left.Equals(right));

            case BinaryOperatorType.BIGGER:
                if (DustType.GetDustType(left) == DustType.Number && DustType.GetDustType(right) == DustType.Number)
                {
                    return(Convert.ToSingle(left) > Convert.ToSingle(right));
                }

                if ((DustType.GetDustType(right) == DustType.String || DustType.GetDustType(right) == DustType.Int) && (DustType.GetDustType(right) == DustType.String || DustType.GetDustType(right) == DustType.Int))
                {
                    if (DustType.GetDustType(left) == DustType.Int)
                    {
                        return((int)left > ((string)right).Length);
                    }

                    if (DustType.GetDustType(right) == DustType.Int)
                    {
                        return(((string)left).Length > (int)right);
                    }

                    return(Convert.ToSingle(left) > Convert.ToSingle(right));
                }

                break;

            case BinaryOperatorType.BIGGER_EQUAL:
                if (DustType.GetDustType(left) == DustType.Number && DustType.GetDustType(right) == DustType.Number)
                {
                    return(Convert.ToSingle(left) >= Convert.ToSingle(right));
                }

                if ((DustType.GetDustType(right) == DustType.String || DustType.GetDustType(right) == DustType.Int) && (DustType.GetDustType(right) == DustType.String || DustType.GetDustType(right) == DustType.Int))
                {
                    if (DustType.GetDustType(left) == DustType.Int)
                    {
                        return((int)left >= ((string)right).Length);
                    }

                    if (DustType.GetDustType(right) == DustType.Int)
                    {
                        return(((string)left).Length >= (int)right);
                    }

                    return(Convert.ToSingle(left) >= Convert.ToSingle(right));
                }

                break;

            case BinaryOperatorType.SMALLER:
                if (DustType.GetDustType(left) == DustType.Number && DustType.GetDustType(right) == DustType.Number)
                {
                    return(Convert.ToSingle(left) < Convert.ToSingle(right));
                }

                if ((DustType.GetDustType(right) == DustType.String || DustType.GetDustType(right) == DustType.Int) && (DustType.GetDustType(right) == DustType.String || DustType.GetDustType(right) == DustType.Int))
                {
                    if (DustType.GetDustType(left) == DustType.Int)
                    {
                        return((int)left < ((string)right).Length);
                    }

                    if (DustType.GetDustType(right) == DustType.Int)
                    {
                        return(((string)left).Length < (int)right);
                    }

                    return(Convert.ToSingle(left) < Convert.ToSingle(right));
                }

                break;

            case BinaryOperatorType.SMALLER_EQUAL:
                if (DustType.GetDustType(left) == DustType.Number && DustType.GetDustType(right) == DustType.Number)
                {
                    return(Convert.ToSingle(left) <= Convert.ToSingle(right));
                }

                if ((DustType.GetDustType(right) == DustType.String || DustType.GetDustType(right) == DustType.Int) && (DustType.GetDustType(right) == DustType.String || DustType.GetDustType(right) == DustType.Int))
                {
                    if (DustType.GetDustType(left) == DustType.Int)
                    {
                        return((int)left <= ((string)right).Length);
                    }

                    if (DustType.GetDustType(right) == DustType.Int)
                    {
                        return(((string)left).Length <= (int)right);
                    }

                    return(Convert.ToSingle(left) <= Convert.ToSingle(right));
                }

                break;
            }

            if (DustType.GetDustType(left) == DustType.Number && DustType.GetDustType(right) == DustType.Number)
            {
                switch (@operator)
                {
                case BinaryOperatorType.PLUS:
                    if (DustType.GetDustType(left) == DustType.Int && DustType.GetDustType(right) == DustType.Int)
                    {
                        return((int)left + (int)right);
                    }

                    return(Convert.ToSingle(left) + Convert.ToSingle(right));

                case BinaryOperatorType.MINUS:
                    if (DustType.GetDustType(left) == DustType.Int && DustType.GetDustType(right) == DustType.Int)
                    {
                        return((int)left - (int)right);
                    }

                    return(Convert.ToSingle(left) - Convert.ToSingle(right));

                case BinaryOperatorType.TIMES:
                    if (DustType.GetDustType(left) == DustType.Int && DustType.GetDustType(right) == DustType.Int)
                    {
                        return((int)left * (int)right);
                    }

                    return(Convert.ToSingle(left) * Convert.ToSingle(right));

                case BinaryOperatorType.DIVIDE:
                    float result = Convert.ToSingle(left) / Convert.ToSingle(right);

                    if (DustType.GetDustType(left) == DustType.Int && DustType.GetDustType(right) == DustType.Int && result % 10 == 0)
                    {
                        return((int)result);
                    }

                    return(result);
                }
            }

            if ((DustType.GetDustType(right) == DustType.String || DustType.GetDustType(right) == DustType.Number) && (DustType.GetDustType(right) == DustType.String || DustType.GetDustType(right) == DustType.Number))
            {
                switch (@operator)
                {
                case BinaryOperatorType.PLUS:
                    if (DustType.GetDustType(right) == DustType.Number)
                    {
                        return((string)left + Convert.ToSingle(right));
                    }

                    if (DustType.GetDustType(left) == DustType.Number)
                    {
                        return(Convert.ToSingle(left) + (string)right);
                    }

                    return((string)left + (string)right);

                case BinaryOperatorType.TIMES:
                    if (DustType.GetDustType(right) == DustType.Number)
                    {
                        return(string.Concat(Enumerable.Repeat((string)left, (int)right).ToArray()));
                    }

                    if (DustType.GetDustType(left) == DustType.Number)
                    {
                        return(string.Concat(Enumerable.Repeat((string)right, (int)left).ToArray()));
                    }

                    break;
                }
            }

            return(null);
        }
예제 #11
0
 protected override string ObjectToString(DustType type, string target, string format)
 {
     switch (type)
     {
         case DustType.Undefined:
             break;
         case DustType.Sql:
             break;
         case DustType.Object:
             break;
         case DustType.Number:
             if (format != null)
             {
                 throw new NotSupportedException("不支持参数");
             }
             return string.Concat("CAST(", target, " as NVARCHAR)");
         case DustType.Array:
             break;
         case DustType.Boolean:
             break;
         case DustType.DateTime:
             switch (format)
             {
                 case "'HH:mm'":
                     return string.Concat("CONVERT(VARCHAR(5),", target, ",114)");
                 case "'HH:mm:ss'":
                     return string.Concat("CONVERT(VARCHAR(8),", target, ",114)");
                 case "'HH:mm:ss.fff'":
                     return string.Concat("CONVERT(VARCHAR(12),", target, ",114)");
                 case "'yyyy-MM-dd'":
                     return string.Concat("CONVERT(VARCHAR(10),", target, ",21)");
                 case "'yyyy-MM-dd HH:mm'":
                     return string.Concat("CONVERT(VARCHAR(16),", target, ",21)");
                 case "'yyyy-MM-dd HH:mm:ss'":
                     return string.Concat("CONVERT(VARCHAR(19),", target, ",21)");
                 case "'yyyy-MM-dd HH:mm:ss.fff'":
                     return string.Concat("CONVERT(VARCHAR(23),", target, ",21)");
                 case "'yy/MM/dd'":
                     return string.Concat("CONVERT(VARCHAR(8),", target, ",111)");
                 case "'yyMMdd'":
                     return string.Concat("CONVERT(VARCHAR(6),", target, ",112)");
                 default:
                     break;
             }
             throw new NotSupportedException("不支持当前参数");
         case DustType.Binary:
             break;
         case DustType.String:
             break;
         default:
             break;
     }
     return base.ObjectToString(type, target, format);
 }
예제 #12
0
    private void _CreateDust(Vector2 pos, DustType rType)
    {
        var instance = _GetDustInstance(rType);

        instance.transform.position = new Vector3(pos.x, pos.y, -2);
    }
예제 #13
0
 public PoolableObject GetDust(DustType type)
 {
     //if (type == DustType.WALK)
     return(dustEffectPools[0].GetObjectDisabled());
 }
예제 #14
0
 protected override string ObjectToString(DustType type, string target, string format)
 {
     switch (type)
     {
         case DustType.Undefined:
             break;
         case DustType.Sql:
             break;
         case DustType.Object:
             break;
         case DustType.Number:
             if (format == null)
             {
                 return string.Concat("TO_CHAR(", target, ")");
             }
             return string.Concat("TO_CHAR(", target, ",", format, ")");
         case DustType.Array:
             break;
         case DustType.Boolean:
             break;
         case DustType.DateTime:
             if (format == null)
             {
                 return string.Concat("TO_CHAR(", target, ",'yyyy-mm-dd HH:mi:ss')");
             }
             format = format.Replace("m", "mi").Replace("mimi", "mi");
             return string.Concat("TO_CHAR(", target, ",", format, ")");
         case DustType.Binary:
             break;
         case DustType.String:
             break;
         default:
             break;
     }
     return base.ObjectToString(type, target, format);
 }
예제 #15
0
 public FunctionDeclaration(string name, FunctionModifier[] modifiers, FunctionParameter[] parameters, Statement[] statements, DustType returnType, DustContext context, Range range)
     : base(range)
 {
     Function = new Function(name, modifiers, parameters, statements, returnType, context, range);
 }
예제 #16
0
파일: BaseSaw.cs 프로젝트: blqw/blqw-Faller
 /// <summary> 解释 Object.ToString 方法
 /// </summary>
 /// <param name="type">调用者类型</param>
 /// <param name="target">方法调用者</param>
 /// <param name="format">格式化参数</param>
 protected virtual string ObjectToString(DustType type, string target, string format)
 {
     throw new NotImplementedException("不支持当前操作,或请重新实现 MethodToString");
 }
예제 #17
0
 /// <summary> 判断最后一次解析结果的类型
 /// </summary>
 /// <param name="type"></param>
 private void CheckDustType(DustType type)
 {
     if (_state.DustType != type)
     {
         if (type != blqw.DustType.Object)
         {
             Throw();
         }
         var code = (int)_state.DustType;
         if (code <= 1 || code > 8)
         {
             Throw();
         }
     }
 }
예제 #18
0
 /// <summary> 验证当前状态
 /// </summary>
 /// <param name="type"></param>
 private void Check(DustType type)
 {
     if (DustType != type)
     {
         throw new NotSupportedException("结果类型错误");
     }
 }
예제 #19
0
        protected override object CompileTypeOfExpression(TypeOfExpression expression)
        {
            object value = CompileExpression(expression.Expression);

            return(DustType.GetDustType(value));
        }
예제 #20
0
        protected override string ObjectToString(DustType type, string target, string format)
        {
            switch (type)
            {
            case DustType.Undefined:
                break;

            case DustType.Sql:
                break;

            case DustType.Object:
                break;

            case DustType.Number:
                if (format != null)
                {
                    throw new NotSupportedException("不支持参数");
                }
                return(string.Concat("CAST(", target, " as NVARCHAR)"));

            case DustType.Array:
                break;

            case DustType.Boolean:
                break;

            case DustType.DateTime:
                switch (format)
                {
                case "'HH:mm'":
                    return(string.Concat("CONVERT(VARCHAR(5),", target, ",114)"));

                case "'HH:mm:ss'":
                    return(string.Concat("CONVERT(VARCHAR(8),", target, ",114)"));

                case "'HH:mm:ss.fff'":
                    return(string.Concat("CONVERT(VARCHAR(12),", target, ",114)"));

                case "'yyyy-MM-dd'":
                    return(string.Concat("CONVERT(VARCHAR(10),", target, ",21)"));

                case "'yyyy-MM-dd HH:mm'":
                    return(string.Concat("CONVERT(VARCHAR(16),", target, ",21)"));

                case "'yyyy-MM-dd HH:mm:ss'":
                    return(string.Concat("CONVERT(VARCHAR(19),", target, ",21)"));

                case "'yyyy-MM-dd HH:mm:ss.fff'":
                    return(string.Concat("CONVERT(VARCHAR(23),", target, ",21)"));

                case "'yy/MM/dd'":
                    return(string.Concat("CONVERT(VARCHAR(8),", target, ",111)"));

                case "'yyMMdd'":
                    return(string.Concat("CONVERT(VARCHAR(6),", target, ",112)"));

                default:
                    break;
                }
                throw new NotSupportedException("不支持当前参数");

            case DustType.Binary:
                break;

            case DustType.String:
                break;

            default:
                break;
            }
            return(base.ObjectToString(type, target, format));
        }
예제 #21
0
 public BoundBinaryOperator(BinaryOperatorKind kind, DustType type)
     : this(kind, type, type, type)
 {
 }