Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        internal static Token Synchronize(HashSet<TokenType> types, Scanner scanner, MessageProducer mp)
        {
            Token tok = scanner.CurrentToken;

            // if the current token is not in the synchronization set
            // then it is unexpected and the parser must recover.
            if (!types.Contains(tok.TokenType))
            {
                // flag the unexpected token
                ErrorHandler.Flag(tok, ErrorCode.UNEXPECTED_TOKEN, mp);

                // recover by skipping tokens that are not in
                // the synchronization set.
                do
                {
                    tok = scanner.GetNextToken();
                } while (!tok.IsEof && !types.Contains(tok.TokenType));
            }
            return tok;
        }