Exemple #1
0
 public void messageReceived(Message message)
 {
     MessageType type = message.type;
     Object[] body = (Object[])message.body;
     switch (type)
     {
         case MessageType.SOURCE_LINE:
             {
                 int lineNumber = (int)body[0];
                 string lineText = (string)body[1];
                 Console.WriteLine(String.Format(SOURCE_LINE_FORMAT, lineNumber, lineText));
                 break;
             }
     }
 }
Exemple #2
0
            public void messageReceived(Message message)
            {
                MessageType type = message.type;
                switch (type)
                {
                    case MessageType.PARSER_SUMMARY:
                        {
                            IConvertible[] body = (IConvertible[])message.body;
                            int statementCount = (int)body[0];
                            int syntaxErrors = (int)body[1];
                            float elapsedTime = (float)body[2];
                            Console.WriteLine(String.Format(PARSER_SUMMARY_FORMAT, statementCount, syntaxErrors, elapsedTime));
                            break;
                        }
                    case MessageType.TOKEN:
                        {
                            Object[] body = (Object[]) message.body;
                            int line = (int) body[0];
                            int position = (int) body[1];
                            TokenType tokenType = (TokenType) body[2];
                            string tokenText = (string)body[3];
                            Object tokenValue = body[4];
                            Console.WriteLine(TOKEN_FORMAT, tokenType, line, position, tokenText);

                            if (tokenValue != null)
                            {
                                if (tokenType == PascalTokenType.STRING)
                                {
                                    tokenValue = "\"" + tokenValue + "\"";
                                }
                                Console.WriteLine(String.Format(VALUE_FORMAT, tokenValue));
                            }

                            break;
                        }
                    case MessageType.SYNTAX_ERROR:
                        {
                            Object[] body = (Object[])message.body;
                            int lineNumber = (int)body[0];
                            int position = (int)body[1];
                            string tokenText = (string)body[2];
                            string errorMessage = (string)body[3];

                            int spaceCount = PREFIX_WIDTH + position;
                            StringBuilder flagBuffer = new StringBuilder();

                            // Spaces up to the error position
                            for (int i = 1; i < spaceCount; ++i)
                                flagBuffer.Append(' ');

                            // A pointer to the error followed by the error message
                            flagBuffer.Append("^\n*** ").Append(errorMessage);

                            // Text, if any, of the bad token.
                            if(tokenText != null)
                                flagBuffer.Append(" [at \"").Append(tokenText).Append("\"]");

                            Console.WriteLine(flagBuffer.ToString());
                            break;
                        }
                }
            }
Exemple #3
0
            public void messageReceived(Message message)
            {
                MessageType type = message.type;
                switch (type)
                {
                    case MessageType.INTERPRETER_SUMMARY:
                        {
                            Object[] body = (Object[])message.body;
                            int executionCount = (int)body[0];
                            int runtimeErrors = (int)body[1];
                            float elapsedTime = (float)body[2];
                            Console.WriteLine(String.Format(INTERPRETER_SUMMARY_FORMAT, executionCount, runtimeErrors, elapsedTime));
                            break;
                        }

                    case MessageType.COMPILER_SUMMARY:
                        {
                            Object[] body = (Object[])message.body;
                            int instructionCount = (int)body[0];
                            float elapsedTime = (float)body[1];
                            Console.WriteLine(String.Format(COMPILER_SUMMARY_FORMAT, instructionCount, elapsedTime));
                            break;
                        }
                }
            }
 public void sendMessage(Message message)
 {
     this.message = message;
     notifyListeners();
 }
Exemple #5
0
 // Notify listeners after setting the message
 public void sendMessage(Message message)
 {
     messageHandler.sendMessage(message);
 }
Exemple #6
0
        public void sendMessage(Message message)
       {
            messageHandler.sendMessage(message);
       }