示例#1
0
 public override Token getToken()
 {
     return(variable.getToken());
 }
示例#2
0
        public override void Semantic()
        {
            left.Semantic();
            if (op.type == Token.Type.DOT)
            {
                if (left is UnaryOp && ((UnaryOp)left).Op == "call" && right is Variable)
                {
                    if (((UnaryOp)left).usingFunction != null)
                    {
                        Function f = ((UnaryOp)left).usingFunction;
                        ((Variable)right).setType(f.Returnt);
                    }
                }
            }
            right.Semantic();

            if (left.assingBlock == null)
            {
                left.assingBlock = assingBlock;
            }
            if (right.assingBlock == null)
            {
                right.assingBlock = assingBlock;
            }

            Variable v = left.TryVariable();
            Variable r = right.TryVariable();

            if (left is BinOp bi)
            {
                if (bi.op.Value == "dot")
                {
                    Console.WriteLine("xxx");
                }
            }
            if (op.Value == "dot" && left is UnaryOp leuop && right is Variable riva)
            {
                if (!(assingBlock.SymbolTable.Get(leuop.OutputType.Value) is Error))
                {
                    Types t = ((Class)assingBlock.SymbolTable.Get(leuop.OutputType.Value)).Block.SymbolTable.Get(riva.Value);
                    if (t is Assign ta)
                    {
                        if (ta.Left is Variable tav)
                        {
                            riva.setType(tav.GetDateType());
                        }
                    }
                    else if (t is Variable tv)
                    {
                        riva.setType(tv.GetDateType());
                    }
                }
            }

            if (op.Value == "dot")
            {
                this.outputType = right.TryVariable().GetDateType();
            }
            else
            {
                this.outputType = v.OutputType(op.type, v, r);
            }

            if (v.Type != "auto")
            {
                if (!v.SupportOp(op.type))
                {
                    Interpreter.semanticError.Add(new Error("#300 Varible type '" + v.Type + "' not support operator " + Variable.GetOperatorStatic(op.type), Interpreter.ErrorType.ERROR, left.getToken()));
                }
                else if (!v.SupportSecond(op.type, right, r))
                {
                    Interpreter.semanticError.Add(new Error("#301 Operator " + Variable.GetOperatorStatic(op.type) + " cannot be applied for '" + v.Type + "' and '" + r.Type + "'", Interpreter.ErrorType.ERROR, op));
                }
            }

            if (op.Value == "dot")
            {
                Console.WriteLine("UnaryOp dot semantic: " + left.getToken().Value + " dot " + right.getToken().Value);
            }
        }
示例#3
0
 public override Token getToken()
 {
     return(expr.getToken());
 }
示例#4
0
 public override Token getToken()
 {
     return(_class.getToken());
 }
示例#5
0
 public override Token getToken()
 {
     return(source.getToken());
 }