Exemple #1
0
 public override void Semantic()
 {
     if (assingBlock.Type != Block.BlockType.CLASS && assingBlock.Type != Block.BlockType.INTERFACE)
     {
         Interpreter.semanticError.Add(new Error("#602 Properties can be used only in Class and Interface!", Interpreter.ErrorType.ERROR, getToken()));
     }
     if (isOneNotDefined)
     {
         Interpreter.semanticError.Add(new Error("#604 Properties must define body!", Interpreter.ErrorType.ERROR, getToken()));
     }
     variable.Semantic();
     setter?.Semantic();
     getter?.Semantic();
 }
Exemple #2
0
 public override void Semantic()
 {
     condition.Semantic();
     left.Semantic();
     right.Semantic();
 }
Exemple #3
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);
            }
        }
Exemple #4
0
 public override void Semantic()
 {
     expr.Semantic();
     block.Semantic();
 }