Пример #1
0
            /**
             * Checks if the next token(s) in the parser matches this
             * token sequence.
             *
             * @param parser         the parser to check
             *
             * @return true if the next tokens are in the sequence, or
             *         false otherwise
             */
            public bool IsNext(Parser parser) {
                Token   token;
                int     id;

                for (int i = 0; i < tokens.Count; i++) {
                    id = (int) tokens[i];
                    token = parser.PeekToken(i);
                    if (token == null || token.Id != id) {
                        return false;
                    }
                }
                return true;
            }
Пример #2
0
            /**
             * Checks if the next token(s) in the parser matches this
             * token sequence.
             *
             * @param parser         the parser to check
             * @param length         the maximum number of tokens to check
             *
             * @return true if the next tokens are in the sequence, or
             *         false otherwise
             */
            public bool IsNext(Parser parser, int length) {
                Token  token;
                int    id;

                if (length > tokens.Count) {
                    length = tokens.Count;
                }
                for (int i = 0; i < length; i++) {
                    id = (int) tokens[i];
                    token = parser.PeekToken(i);
                    if (token == null || token.Id != id) {
                        return false;
                    }
                }
                return true;
            }
Пример #3
0
        /**
         * Checks if the next token(s) in the parser match any token
         * sequence in this set.
         *
         * @param parser         the parser to check
         * @param length         the maximum number of tokens to check
         *
         * @return true if the next tokens are in the set, or
         *         false otherwise
         */
        public bool IsNext(Parser parser, int length) {
            Sequence  seq;

            for (int i = 0; i < elements.Count; i++) {
                seq = (Sequence) elements[i];
                if (seq.IsNext(parser, length)) {
                    return true;
                }
            }
            return false;
        }