Example #1
0
        public void process(ReadStatment readStatment)
        {
            try
            {
                VaribleStatment varibleStatment = (VaribleStatment)readStatment.getTokensList()[0];
                _isArray    = false;
                _identifier = (Token)varibleStatment.getTokensList()[0];
                SemanticAnalizer.initVarible(_identifier.value);
            }
            catch//для массива
            {
                _isArray = true;
                List <Token> tokens = AssignmentProcessor.getMathExpression((MathStatment)readStatment.getTokensList()[0]);
                _identifier = tokens[0];
                if (tokens.Count == 1)
                {
                    if (tokens[0].kind == Constants.CONST_INT)
                    {
                        SemanticAnalizer.readAndWriteToConts();
                    }

                    _isArray = false;
                }
                else if (tokens.Count == 4 && (tokens[1].kind == Constants.BRACKET_L) && (tokens[3].kind == Constants.BRACKET_R))
                {
                    _isArray      = true;
                    _elementIndex = tokens[2];
                }
                else
                {
                    SemanticAnalizer.InvalidIdentifier();
                }
            }
            generate();
        }
Example #2
0
        public void process(AssignmentStatment assignmentStatment)
        {
            VaribleStatment varibleStatment = (VaribleStatment)assignmentStatment.getTokensList()[0];

            if (varibleStatment.getTokensList().Count == 1) // для переменной
            {
                _isArrayElementLeft = false;
                _leftOp             = (Token)varibleStatment.getTokensList()[0];
                Program.varibleName = _leftOp.value;
                SemanticAnalizer.initVarible(_leftOp.value);

                _rightOp = getRightOp(assignmentStatment.getTokensList()[1]);
            }
            else //элемент массива
            {
                _isArrayElementLeft = true;
                _leftOp             = (Token)varibleStatment.getTokensList()[0];
                Program.varibleName = _leftOp.value;
                _elementIndex       = (Token)varibleStatment.getTokensList()[2];
                List <Token> rightOp = getRightOp(assignmentStatment.getTokensList()[1]);
                SemanticAnalizer.checkArrayOnOutOfRange(rightOp);
            }
            //SemanticAnalizer.checkDivByZero(_rightOp);
            //SemanticAnalizer.checkArrayOnOutOfRange(_rightOp);
            generate();
        }
Example #3
0
        public static List <Token> addFactor(VaribleStatment varibleStatment)
        {
            List <Token> tokens = new List <Token>();

            foreach (object element in varibleStatment.getTokensList())
            {
                tokens.Add((Token)element);
            }

            SemanticAnalizer.checkVarible(tokens[0].value);

            if (tokens.Count == 4)
            {
                if (tokens[2].kind == Constants.IDENTIFIER)
                {
                    SemanticAnalizer.checkVarible(tokens[2].value);
                }
                else
                {
                    SemanticAnalizer.checkGetElementByIndex(Program.varibleName, Int32.Parse(tokens[2].value));
                }
            }

            return(tokens);
        }
Example #4
0
        public void process(VaribleDeclaration varibleDeclaration)
        {
            Token _identifier = (Token)varibleDeclaration.getTokensList()[0]; //рассказать про косяк сереге
            Type  type        = (Type)varibleDeclaration.getTokensList()[1];

            try //для массива
            {
                ArrayType arrayType = (ArrayType)type.getTokensList()[0];
                _isArray = true;
                _type    = (Token)arrayType.getTokensList()[0];
                _length  = (Token)arrayType.getTokensList()[1];
                SemanticAnalizer.checkIsDefineAgain(_identifier.value);
                SemanticAnalizer.checkInitEmptyArray(_identifier.value, Int32.Parse(_length.value));
                SemanticAnalizer.addVarible(_identifier.value, _type.value, Int32.Parse(_length.value));
            }
            catch  // для инта
            {
                IntegerType integerType = (IntegerType)type.getTokensList()[0];
                _isArray = false;
                _type    = (Token)integerType.getTokensList()[0];
                SemanticAnalizer.checkIsDefineAgain(_identifier.value);
                SemanticAnalizer.addVarible(_identifier.value, _type.value);
            }

            generate();
        }
Example #5
0
        public void process(WhileStatment whileStatment)
        {
            BoolStatment boolSatment = (BoolStatment)whileStatment.getTokensList()[0];

            _leftExpression = IfStatmentProcessor.getLeftExpression((BoolExpression)boolSatment.getTokensList()[0]);
            if (_leftExpression[0].kind == Constants.IDENTIFIER)
            {
                SemanticAnalizer.checkVarible(_leftExpression[0].value);
            }
            if (_leftExpression[2].kind == Constants.IDENTIFIER)
            {
                SemanticAnalizer.checkVarible(_leftExpression[2].value);
            }
            _rightExpression = IfStatmentProcessor.getElseAndThenStatments((StatmentPart)whileStatment.getTokensList()[1]);
            generate();
        }
        public static List <Token> getMathExpression(MathStatment mathStatment)
        {
            List <Token>   tokens         = new List <Token>();
            MathExpression mathExpression = (MathExpression)mathStatment.getTokensList()[0];

            foreach (object item in mathExpression.getTokensList())
            {
                tokens.AddRange(getFactor(item));
            }


            if (!Program.isArrayElementLeft)
            {
                SemanticAnalizer.checkCompareTypes(Program.varibleName, Constants.INT);
            }

            return(tokens);
        }
Example #7
0
        List <Token> getArrayInitializtionList(ArrayAssignment arrayAssignmnent)
        {
            List <Token> tokens = new List <Token>();

            foreach (Token token in arrayAssignmnent.getTokensList())
            {
                tokens.Add(token);
            }
            SemanticAnalizer.checkVarible(_leftOp.value);
            SemanticAnalizer.checkInitEmptyArray(_leftOp.value, tokens.Count);
            SemanticAnalizer.checkIsLengthArrayEqual(_leftOp.value, tokens.Count);

            if (_isArrayElementLeft)
            {
                SemanticAnalizer.incompatibleTypes();
            }
            else
            {
                SemanticAnalizer.checkCompareTypes(_leftOp.value, Constants.INTARRAY);
            }

            return(tokens);
        }
Example #8
0
        public void process(IfStatment ifStatment)
        {
            isElseAppear = false;
            BoolStatment boolStatment = (BoolStatment)ifStatment.getTokensList()[0];

            _leftExpression = getLeftExpression((BoolExpression)boolStatment.getTokensList()[0]);
            if (_leftExpression[0].kind == Constants.IDENTIFIER)
            {
                SemanticAnalizer.checkVarible(_leftExpression[0].value);
            }
            if (_leftExpression[2].kind == Constants.IDENTIFIER)
            {
                SemanticAnalizer.checkVarible(_leftExpression[2].value);
            }
            _thenExpression = getElseAndThenStatments((StatmentPart)ifStatment.getTokensList()[1]);

            if (ifStatment.getTokensList().Count == 3)
            {
                isElseAppear    = true;
                _elseExpression = getElseAndThenStatments((StatmentPart)ifStatment.getTokensList()[2]);
            }
            generate();
        }