コード例 #1
0
        //*
        // * Checks if the next tokens match a production pattern
        // * alternative. The pattern alternative look-ahead set will be
        // * used if existing, otherwise this method returns false.
        // *
        // * @param alt the pattern alternative to check
        // *
        // * @return true if the next tokens match, or
        // * false otherwise
        //

        private bool IsNext(ProductionPatternAlternative alt)
        {
            LookAheadSet @set = alt.LookAhead;

            if (@set == null)
            {
                return(false);
            }
            else
            {
                return(@set.IsNext(this));
            }
        }
コード例 #2
0
        //*
        // * Checks if the next tokens match a production pattern. The
        // * pattern look-ahead set will be used if existing, otherwise
        // * this method returns false.
        // *
        // * @param pattern the pattern to check
        // *
        // * @return true if the next tokens match, or
        // * false otherwise
        //

        private bool IsNext(ProductionPattern pattern)
        {
            LookAheadSet @set = pattern.LookAhead;

            if (@set == null)
            {
                return(false);
            }
            else
            {
                return(@set.IsNext(this));
            }
        }
コード例 #3
0
        //*
        // * Checks if the next tokens match a production pattern
        // * element. If the element has a look-ahead set it will be
        // * used, otherwise the look-ahead set of the referenced
        // * production or token will be used.
        // *
        // * @param elem the pattern element to check
        // *
        // * @return true if the next tokens match, or
        // * false otherwise
        //

        private bool IsNext(ProductionPatternElement elem)
        {
            LookAheadSet @set = elem.LookAhead;

            if (@set != null)
            {
                return(@set.IsNext(this));
            }
            else if (elem.IsToken())
            {
                return(elem.IsMatch(PeekToken(0)));
            }
            else
            {
                return(IsNext(GetPattern(elem.Id)));
            }
        }
コード例 #4
0
        //*
        // * Throws a parse exception that matches the specified look-ahead
        // * set. This method will take into account any initial matching
        // * tokens in the look-ahead set.
        // *
        // * @param set the look-ahead set to match
        // *
        // * @throws ParseException always thrown by this method
        //

        private void ThrowParseException(LookAheadSet @set)
        {
            Token     token = default(Token);
            ArrayList list  = new ArrayList();

            int[] initials = null;

            // Read tokens until mismatch
            while (@set.IsNext(this, 1))
            {
                @set = @set.CreateNextSet(NextToken().Id);
            }

            // Find next token descriptions
            initials = @set.GetInitialTokens();
            for (int i = 0; i <= initials.Length - 1; i++)
            {
                list.Add(GetTokenDescription(initials[i]));
            }

            // Create exception
            token = NextToken();
            throw new ParseException(ParseException.ErrorType.UNEXPECTED_TOKEN, token.ToShortString(), list, token.StartLine, token.StartColumn);
        }