Esempio n. 1
0
        /// <summary>
        /// Adds a global temporary.
        /// </summary>
        /// <returns>The global temporary.</returns>
        /// <param name="type">Type.</param>
        public static Variable AddGlobalTemporary(GraphicFooType type)
        {
            string   id       = temporaryPrefix + globalTemporary.GetCount();
            Variable variable = new Variable(id, type);

            globalTemporary.AddVariable(variable);
            return(variable);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a temporary variable.
        /// </summary>
        /// <returns>The temporary variable.</returns>
        /// <param name="type">Type.</param>
        public Variable AddTemporaryVariable(GraphicFooType type)
        {
            string   id       = temporaryPrefix + temporaryVariables.GetCount();
            Variable variable = new Variable(id, type);

            temporaryVariables.AddVariable(variable);
            return(variable);
        }
Esempio n. 3
0
        /// <summary>
        /// Parser function that generates function call quadruples.
        /// While checking semantics.
        /// </summary>
        void CallFunction()
        {
            Expect((int)TokenEnum.Function);
            Expect((int)TokenEnum.Id);
            string id = GetLastTokenValue();

            Expect((int)TokenEnum.LeftParenthesis);
            VariableBlock parameters = new VariableBlock();

            if (StartOf((int)TokenEnum.String))
            {
                Expression();
                string         paramId   = Quadruple.operandStack.Pop();
                GraphicFooType type      = Quadruple.typeStack.Pop();
                Variable       parameter = new Variable(paramId, type);
                if (parameter.type == GraphicFooType.Invalid)
                {
                    SemErr((int)SemanticEnum.Variable);
                }
                parameters.AddVariable(parameter);
                while (la.kind == (int)TokenEnum.Comma)
                {
                    Get();
                    Expression();
                    paramId   = Quadruple.operandStack.Pop();
                    type      = Quadruple.typeStack.Pop();
                    parameter = new Variable(paramId, type);
                    if (parameter.type == GraphicFooType.Invalid)
                    {
                        SemErr((int)SemanticEnum.Variable);
                    }
                    parameters.AddVariable(parameter);
                }
            }
            Expect((int)TokenEnum.RightParenthesis);
            Quadruple.CreateFunctionCallQuadruples(id, parameters);

            if (la.kind == (int)TokenEnum.Assignation)
            {
                Get();
                Expect((int)TokenEnum.Id);
                string varId = GetLastTokenValue();
                Quadruple.CreateReturnAssignationQuadruple(id, varId);
            }
            Expect((int)TokenEnum.Semicolon);
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a constant.
        /// </summary>
        /// <returns>The constant.</returns>
        /// <param name="id">Identifier.</param>
        /// <param name="type">Type.</param>
        public static Variable AddConstant(string id, GraphicFooType type)
        {
            if (constants.Contains(id))
            {
                return(constants.ReadVariable(id));
            }
            Variable variable = new Variable(id, type);

            constants.AddVariable(variable);
            return(variable);
        }
Esempio n. 5
0
        Procedure FunctionHeader()
        {
            Expect((int)TokenEnum.Function);
            Expect((int)TokenEnum.Id);
            string id = GetLastTokenValue();

            Expect((int)TokenEnum.LeftParenthesis);

            VariableBlock parameters = null;

            if (StartOf((int)TokenEnum.Id))
            {
                parameters = new VariableBlock();
                Type();
                string varType = GetLastTokenValue();
                Expect((int)TokenEnum.Id);
                string   varId     = GetLastTokenValue();
                Variable parameter = new Variable(varId, varType);
                if (parameter.type == GraphicFooType.Invalid)
                {
                    SemErr((int)SemanticEnum.Variable);
                }
                parameters.AddVariable(parameter);
                while (la.kind == (int)TokenEnum.Comma)
                {
                    Get();
                    Type();
                    varType = GetLastTokenValue();
                    Expect((int)TokenEnum.Id);
                    varId     = GetLastTokenValue();
                    parameter = new Variable(varId, varType);
                    parameters.AddVariable(parameter);
                }
            }
            Expect((int)TokenEnum.RightParenthesis);
            Expect((int)TokenEnum.Colon);
            Type();
            string type = GetLastTokenValue();

            return(ProgramMemory.AddProcedure(id, type, parameters));
        }
Esempio n. 6
0
        /// <summary>
        /// Adds a variable.
        /// </summary>
        /// <param name="id">Identifier.</param>
        /// <param name="type">Type.</param>
        public void AddVariable(string id, string type)
        {
            Variable variable = new Variable(id, type);

            procedureVariables.AddVariable(variable);
        }
Esempio n. 7
0
        /// <summary>
        /// Adds a global variable.
        /// </summary>
        /// <param name="id">Identifier.</param>
        /// <param name="type">Type.</param>
        public static void AddGlobalVariable(string id, string type)
        {
            Variable variable = new Variable(id, type);

            globalVariables.AddVariable(variable);
        }