Пример #1
0
        public String operatorToString(ComparingOperator compOperator)
        {
            String operatorString = "";

            if (compOperator == ComparingOperator.EQUAL)
            {
                operatorString = " == ";
            }
            else if (compOperator == ComparingOperator.GREATER)
            {
                operatorString = " > ";
            }
            else if (compOperator == ComparingOperator.GREATER_OR_EQUAL)
            {
                operatorString = " >= ";
            }
            else if (compOperator == ComparingOperator.LESS)
            {
                operatorString = " < ";
            }
            else if (compOperator == ComparingOperator.LESS_OR_EQUAL)
            {
                operatorString = " <= ";
            }
            else if (compOperator == ComparingOperator.UNEQUAL)
            {
                operatorString = " != ";
            }
            return(operatorString);
        }
        public bool Visit(ComparingOperator node)
        {
            if (node.SymType != null)
            {
                return(true);
            }

            node.Left.Accept(this);
            node.Right.Accept(this);

            // we can use additive operators only with integer and float (all operators),
            // char and boolean and nil and any pointer ('=', '<>')
            var lType = (node.Left.SymType as SymAliasType)?.GetBase() ?? node.Left.SymType;
            var rType = (node.Right.SymType as SymAliasType)?.GetBase() ?? node.Right.SymType;

            if (lType.GetType() == typeof(SymRecordType) || rType.GetType() == typeof(SymRecordType) ||
                lType.GetType() == typeof(SymArrayType) || rType.GetType() == typeof(SymArrayType) ||
                !((node.Token.Type == TokenType.EqualOperator || node.Token.Type == TokenType.NotEqualOperator) &&
                  (lType.Equals(SymbolStack.SymBool) && rType.Equals(SymbolStack.SymBool) ||
                   lType.Equals(SymbolStack.SymChar) && rType.Equals(SymbolStack.SymChar) ||
                   (lType.Equals(SymbolStack.SymNil) || rType.GetType() == typeof(SymPointerType)) &&
                   (lType.GetType() == typeof(SymPointerType) || rType.Equals(SymbolStack.SymNil))) ||
                  (lType.Equals(SymbolStack.SymInt) || lType.Equals(SymbolStack.SymFloat)) &&
                  (rType.Equals(SymbolStack.SymInt) || rType.Equals(SymbolStack.SymFloat))))
            {
                throw new Exception(string.Format("({0}, {1}) semantic error: incompatible types: '{2}' {3} '{4}'",
                                                  node.Token.Line, node.Token.Column, node.Left.SymType, node.Token.Value, node.Right.SymType));
            }

            node.SymType  = SymbolStack.SymBool;
            node.IsLValue = false;
            return(true);
        }
        private Expression ParseExpression()
        {
            var left = ParseSimpleExpression();

            if (left == null)
            {
                //exception unexpected something
                return(null);
            }

            while (true)
            {
                var operatorToken = PeekToken();
                if (operatorToken == null || !ComparingOperators.Contains(operatorToken.Type))
                {
                    break;
                }

                NextToken();
                var right = ParseSimpleExpression();
                left = new ComparingOperator(operatorToken, left, right);
            }

            return(left);
        }
Пример #4
0
        public AstPrinterNode Visit(ComparingOperator node)
        {
            var printer = new AstPrinterNode(node.ToString());

            printer.AddChild(node.Left.Accept(this));
            printer.AddChild(node.Right.Accept(this));
            return(printer);
        }
Пример #5
0
        public void bttEdit_Click(object sender, EventArgs e)
        {
            int    selectedIndex = listboxEntries.SelectedIndex;
            String assignmentConstraintString = "";

            if (selectedIndex != -1)
            {
                //attributeAssignment
                if (radioSet.Checked && cmbAttributes.Text != "")
                {
                    SQLAttribute        leftAttribute   = this.leftAttributes[cmbAttributes.SelectedIndex] as SQLAttribute;
                    AttributeAssignment attAssignment   = new AttributeAssignment(repository, objectVariable, leftAttribute);
                    Expression          rightExpression = ConstraintExpressionProvider.getExpression();
                    if (rightExpression != null)
                    {
                        attAssignment.ValueExpression = rightExpression;
                        this.assignmentsAndConstraints.RemoveAt(selectedIndex);
                        this.assignmentsAndConstraints.Insert(selectedIndex, attAssignment);
                        assignmentConstraintString = attAssignment.ToString();
                    }
                }


                //constraint
                else if (!radioSet.Checked && cmbAttributes.Text != "")
                {
                    SQLAttribute leftAttribute = this.leftAttributes[cmbAttributes.SelectedIndex];
                    EAEcoreAddin.Modeling.SDMModeling.SDMExportWrapper.patterns.Constraint constraint = new EAEcoreAddin.Modeling.SDMModeling.SDMExportWrapper.patterns.Constraint(repository);

                    ComparisonExpression compExp           = new ComparisonExpression(repository);
                    ComparingOperator    comparingOperator = ComparingOperator.EQUAL;
                    if (radioEqual.Checked)
                    {
                        comparingOperator = ComparingOperator.EQUAL;
                    }
                    else if (radioGreater.Checked)
                    {
                        comparingOperator = ComparingOperator.GREATER;
                    }
                    else if (radioLess.Checked)
                    {
                        comparingOperator = ComparingOperator.LESS;
                    }
                    else if (radioLessEqual.Checked)
                    {
                        comparingOperator = ComparingOperator.LESS_OR_EQUAL;
                    }
                    else if (radioNotEqual.Checked)
                    {
                        comparingOperator = ComparingOperator.UNEQUAL;
                    }
                    else if (radioGreaterEqual.Checked)
                    {
                        comparingOperator = ComparingOperator.GREATER_OR_EQUAL;
                    }
                    compExp.Operator       = comparingOperator;
                    compExp.LeftExpression = new AttributeValueExpression(repository, leftAttribute, objectVariable.sqlElement);
                    Expression rightExpression = ConstraintExpressionProvider.getExpression();
                    if (rightExpression != null)
                    {
                        compExp.RightExpression         = rightExpression;
                        constraint.ConstraintExpression = compExp;
                        this.assignmentsAndConstraints.RemoveAt(selectedIndex);
                        this.assignmentsAndConstraints.Insert(selectedIndex, constraint);
                        assignmentConstraintString = constraint.ToString();
                    }
                }
                internalAssignmentConstraintListToOVLists();
                addAssignmentsAndConstraintsToListboxNew();

                listboxEntries.SelectedItem = assignmentConstraintString;
            }
            this.expressionControl.setInformationLossPossible(false);
        }
Пример #6
0
        private void bttAdd_Click(object sender, EventArgs e)
        {
            String assignmentConstraintString = "";

            //attributeAssignment
            if (radioSet.Checked && cmbAttributes.Text != "")
            {
                SQLAttribute        leftAttribute   = this.leftAttributes[cmbAttributes.SelectedIndex] as SQLAttribute;
                AttributeAssignment attAssignment   = new AttributeAssignment(repository, this.objectVariable, leftAttribute);
                Expression          rightExpression = ConstraintExpressionProvider.getExpression();
                if (rightExpression != null)
                {
                    attAssignment.ValueExpression = rightExpression;
                    this.objectVariable.AttributeAssignments.Add(attAssignment);
                    String assignmentString = attAssignment.ToString();
                    listboxEntries.Items.Add(assignmentString);

                    assignmentConstraintString = assignmentString;
                }
            }

            //constraint
            else if (!radioSet.Checked && cmbAttributes.Text != "")
            {
                SQLAttribute leftAttribute = this.leftAttributes[cmbAttributes.SelectedIndex];
                EAEcoreAddin.Modeling.SDMModeling.SDMExportWrapper.patterns.Constraint constraint = new EAEcoreAddin.Modeling.SDMModeling.SDMExportWrapper.patterns.Constraint(repository);

                ComparisonExpression compExp           = new ComparisonExpression(repository);
                ComparingOperator    comparingOperator = ComparingOperator.EQUAL;
                if (radioEqual.Checked)
                {
                    comparingOperator = ComparingOperator.EQUAL;
                }
                else if (radioGreater.Checked)
                {
                    comparingOperator = ComparingOperator.GREATER;
                }
                else if (radioLess.Checked)
                {
                    comparingOperator = ComparingOperator.LESS;
                }
                else if (radioLessEqual.Checked)
                {
                    comparingOperator = ComparingOperator.LESS_OR_EQUAL;
                }
                else if (radioNotEqual.Checked)
                {
                    comparingOperator = ComparingOperator.UNEQUAL;
                }
                else if (radioGreaterEqual.Checked)
                {
                    comparingOperator = ComparingOperator.GREATER_OR_EQUAL;
                }
                compExp.Operator = comparingOperator;

                compExp.LeftExpression = new AttributeValueExpression(repository, leftAttribute, objectVariable.sqlElement);
                Expression rightExpression = ConstraintExpressionProvider.getExpression();
                if (rightExpression != null)
                {
                    compExp.RightExpression         = rightExpression;
                    constraint.ConstraintExpression = compExp;
                    this.objectVariable.Constraints.Add(constraint);
                    String constraintString = constraint.ToString();
                    listboxEntries.Items.Add(constraintString);

                    assignmentConstraintString = constraintString;
                }
            }
            addAssignmentsAndConstraintsToListboxNew();

            if (assignmentConstraintString != "")
            {
                listboxEntries.SelectedItem = assignmentConstraintString;
                //listBoxSelectedIndexChangedNew(null, null);
            }
            this.expressionControl.setInformationLossPossible(false);
        }