Exemplo n.º 1
0
        public object Execute(ICodeNode node, ref int exec_count)
        {
            switch (node.Type)
            {
                case ICodeNodeType.VARIABLE:
                    {
                        // Get the variable's symbol table entry and return its value.
                        SymbolTableEntry entry = (SymbolTableEntry)node.GetAttribute(ICodeKey.ID);
                        return entry.GetAttribute(SymbolTableKey.DataValue);
                    }
                case ICodeNodeType.INTEGER_CONSTANT:
                    {
                        // Return the integer value.
                        return node.GetAttribute(ICodeKey.VALUE);
                    }
                case ICodeNodeType.REAL_CONSTANT:
                    {
                        // Return the integer value.
                        return node.GetAttribute(ICodeKey.VALUE);
                    }
                case ICodeNodeType.STRING_CONSTANT:
                    {
                        // Return the integer value.
                        return node.GetAttribute(ICodeKey.VALUE);
                    }
                case ICodeNodeType.NEGATE:
                    {
                        // Get the NEGATE node's expression node child.
                        List<ICodeNode> children = node.GetChildren();
                        ICodeNode expression = children[0];

                        // Execute the expression and return the negative of its value.
                        object value = Execute(expression, ref exec_count);
                        if (value is int)
                        {
                            return -(int)value;
                        } else if (value is double)
                        {
                            return -(double)value;
                        } else
                        {
                            return null;
                        }
                    }
                case ICodeNodeType.NOT:
                    {
                        // Get the NOT node's expression node child.
                        List<ICodeNode> children = node.GetChildren();
                        ICodeNode expression = children[0];

                        // Execute the expression and return the "not" of its value
                        bool value = (bool)Execute(expression, ref exec_count);
                        return !value;
                    }
                default:
                    // must be a binary operator
                    return ExecuteBinaryOperator(node, ref exec_count);
            }
        }
Exemplo n.º 2
0
        public static void Flag(ICodeNode node, RuntimeErrorCode error_code, MessageProducer backend)
        {
            //string line_number = null;
            while (node != null && node.GetAttribute(ICodeKey.LINE) == null)
            {
                node = node.Parent;
            }

            // notify observers
            var args = (Tuple<string, int>)Tuple.Create(error_code.Message, (int)node.GetAttribute(ICodeKey.LINE));
            Message msg = new Message(MessageType.RuntimeError, args);
            backend.Send(msg);

            if (++Errors > MAX_ERRORS)
            {
                Console.WriteLine("*** ABORTED AFTER TOO MANY RUNTIME ERRORS.*");
                Environment.Exit(-1);
            }
        }
Exemplo n.º 3
0
        private void SendMessage(ICodeNode node, string variable_name, object value)
        {
            object line_number = node.GetAttribute(ICodeKey.LINE);

            // Send an ASSIGN message.
            if (line_number != null)
            {
                var args = Tuple.Create((int)line_number, variable_name, (object)value);
                Message msg = new Message(MessageType.Assign, args);
                Send(msg);
            }
        }
Exemplo n.º 4
0
        private void SendSourceLineMessage(ICodeNode node)
        {
            object line_number = node.GetAttribute(ICodeKey.LINE);

            // send the SourceLine message
            if (line_number != null)
            {
                var args = (Tuple<int>)Tuple.Create((int)line_number);
                Message msg = new Message(MessageType.SourceLine, args);
                Send(msg);
            }
        }