Example #1
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 #2
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 #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);
        }