Пример #1
0
        /// <summary>
        /// Builds a new CallFunction command for a routine (no return value)
        /// and adds it to current scope.
        /// </summary>
        /// <param name="function">Function to be called.</param>
        /// <param name="parameters">Symbols corresponding to the function's
        /// parameters.</param>
        private void DoRoutine(Function function, List <DirectValueSymbol> parameters)
        {
            if (function.Type != Type.Rutina)
            {
                SemErr("La función no es una rutina.");
                return;
            }

            for (var para = 0; para < parameters.Count; para++)
            {
                if (_cube[(int)function.Parameters[para].Type, (int)parameters[para].Type,
                          (int)Operator.Asignation] == Type.Error)
                {
                    SemErr("Error de tipos");
                    return;
                }
            }

            var cmd = new CallFunction
            {
                Function    = function,
                ScopeCalled = _currentScope,
                Parameters  = parameters
            };

            _currentScope.CommandList.Commands.Add(cmd);
        }
Пример #2
0
        /// <summary>
        /// Builds a new CallFunction command and adds it to current scope.
        /// </summary>
        /// <param name="function">Function to be called</param>
        /// <param name="parameters">Symbols that correspond to the parameters.
        /// </param>
        /// <param name="result">Symbol where result will be stored.</param>
        private void DoFunction(Function function, List <DirectValueSymbol> parameters, DirectValueSymbol result)
        {
            if (function.Type == Type.Rutina)
            {
                SemErr("La función no tiene un valor de retorno.");
                return;
            }

            for (var para = 0; para < parameters.Count; para++)
            {
                if (_cube[(int)function.Parameters[para].Type, (int)parameters[para].Type,
                          (int)Operator.Asignation] != function.Parameters[para].Type)
                {
                    SemErr("Error de tipos");
                    return;
                }
            }

            result.Type = function.Type;

            var cmd = new CallFunction
            {
                Function    = function,
                ScopeCalled = _currentScope,
                Result      = result,
                Parameters  = parameters
            };

            _currentScope.CommandList.Commands.Add(cmd);
        }