Exemple #1
0
        void Assignation(string type = "")
        {
            bool assign = false;

            Expect((int)TokenEnum.Id);
            string   id       = GetLastTokenValue();
            Variable variable = ProgramMemory.FindVariable(scope, id);

            if (variable == null && type == "")
            {
                SemErr((int)SemanticEnum.NotDeclared);
            }
            if (la.kind == (int)TokenEnum.Assignation)
            {
                Get();
                Expression();
                assign = true;
            }
            Expect((int)TokenEnum.Semicolon);

            if (type != "")
            {
                if (scope == null)
                {
                    ProgramMemory.AddGlobalVariable(id, type);
                }
                else
                {
                    scope.AddVariable(id, type);
                }
            }

            if (assign)
            {
                try {
                    string temp = Quadruple.operandStack.Pop();
                    Quadruple.CreateAssignationQuadruple(temp, id);
                } catch (InvalidOperationException) {
                    SynErr((int)TokenEnum.NoExpression);
                }
            }
        }