Пример #1
0
        public void GenerateCode(ArithmeticOperationNode node, ICIL_CodeGenerator codeGenerator)
        {
            node.Holder = codeGenerator.DefineVariable();

            codeGenerator.AddLocalVariable(
                new CIL_LocalVariable((Variable)node.Holder));

            GenerateCode(node.OpNode1, codeGenerator);
            GenerateCode(node.OpNode2, codeGenerator);

            switch (node)
            {
            case AdditionNode additionNode:
                codeGenerator.AddInstruction(
                    new CilPlus((Variable)additionNode.Holder, node.OpNode1.Holder, node.OpNode2.Holder));
                break;

            case DivisionNode divisionNode:

                codeGenerator.AddInstruction(
                    new CilDiv((Variable)divisionNode.Holder, node.OpNode1.Holder, node.OpNode2.Holder));
                break;

            case MultiplicationNode multiplicationNode:
                codeGenerator.AddInstruction(
                    new CilMult((Variable)multiplicationNode.Holder, node.OpNode1.Holder, node.OpNode2.Holder));
                break;

            case SubstractionNode substractionNode:
                codeGenerator.AddInstruction(
                    new CilMinus((Variable)substractionNode.Holder, node.OpNode1.Holder, node.OpNode2.Holder));

                break;
            }
        }
Пример #2
0
    public void ToNodes(ICodeNode parentNode)
    {
        RootNode rootNode = parentNode.GetRootNode();
        ArithmeticOperationNode arithOpNode = CreateNode(rootNode);

        parentNode.AddChildNode(arithOpNode);
    }
Пример #3
0
    public ArithmeticOperationNode CreateNode(RootNode rootNode)
    {
        HighlightableButton highlightableButton = (GameObjectHelper.HasComponent <HighlightableButton>(this.gameObject)) ? this.GetComponent <HighlightableButton>() : null;
        IntegerNode         field1 = GetField1Node(rootNode);
        IntegerNode         field2 = GetField2Node(rootNode);

        // Converts the arithmetic operator choosen to the proper enum
        ArithmeticOperationNode.ArithmeticOperation operation = GetOperation(GetOperator());
        ArithmeticOperationNode arithOpNode = new ArithmeticOperationNode(highlightableButton, field1, field2, operation);

        return(arithOpNode);
    }
Пример #4
0
        public void CheckSemantic(ArithmeticOperationNode node, IScope scope = null)
        {
            CheckSemantic(node.OpNode1, scope);
            CheckSemantic(node.OpNode2, scope);

            TypeTable.IsDefinedType("Int", out var intergerType);
            if (node.OpNode1.ComputedType != intergerType || node.OpNode2.ComputedType != intergerType)
            {
                Logger.LogError(node.Line, node.CharPositionInLine,
                                $"Cannot implicitly convert type '{node.OpNode1.ComputedType}' to '{node.OpNode2.ComputedType}'");
                return;
            }
            node.ComputedType = intergerType;
        }
 public void Visit(ArithmeticOperationNode node)
 {
     if (node.Attributes.ContainsKey("integer_constant_value"))
     {
         Code.Add(new AssignmentConstantToVariableCodeLine(VariableManager.PeekVariableCounter(), node.Attributes["integer_constant_value"]));
     }
     else
     {
         BinaryOperationVisit(node);
     }
     if (object_return_type)
     {
         SetReturnType("Int");
     }
 }
Пример #6
0
    public void ToNodes(ICodeNode parentNode)
    {
        RootNode            rootNode            = parentNode.GetRootNode();
        HighlightableButton highlightableButton = (GameObjectHelper.HasComponent <HighlightableButton>(this.gameObject)) ? this.GetComponent <HighlightableButton>() : null;

        //Checks if this blox has a param if it has creates an ArithmeticOperationNode instead of an Integer node
        if (this.BloxParams.Count > 0)
        {
            ArithmeticOperatorBlox  arithOpBlox = BloxParams[0].GetComponent <ArithmeticOperatorBlox>();
            ArithmeticOperationNode arithOpNode = arithOpBlox.CreateNode(rootNode);
            arithOpNode.NodeName = this.GetName();
            parentNode.AddChildNode(arithOpNode);
        }
        else
        {
            IntegerNode intNode = new IntegerNode(highlightableButton, GetValueAsInt());
            intNode.NodeName = this.GetName();
            parentNode.AddChildNode(intNode);
        }
    }
        public void Visit(ArithmeticOperationNode node)
        {
            node.LeftOperand.Accept(this);
            node.RightOperand.Accept(this);

            if (node.LeftOperand.StaticType.Text != node.RightOperand.StaticType.Text)
            {
                errors.Add(SemanticError.InvalidUseOfOperator(node, node.LeftOperand.StaticType, node.RightOperand.StaticType));
            }

            else if (node.LeftOperand.StaticType.Text != "Int" || node.RightOperand.StaticType.Text != "Int")
            {
                errors.Add(SemanticError.InvalidUseOfOperator(node));
            }

            else if (!scope.IsDefinedType("Int", out node.StaticType))
            {
                errors.Add(SemanticError.NotDeclaredType(new TypeNode(node.Line, node.Column, "Int")));
            }
        }
 public static string InvalidUseOfOperator(ArithmeticOperationNode node)
 {
     return($"({node.Line}, {node.Column}) - Semantic Error" +
            $" Operator '{node.Symbol}' must be applied to types 'Int'."
            );
 }
 public void Visit(ArithmeticOperationNode node)
 {
     throw new NotImplementedException();
 }