Exemple #1
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;
        }