Пример #1
0
        //*
        // * Checks a production pattern for completeness. If some rule
        // * in the pattern referenced an production pattern not added
        // * to this parser, a parser creation exception will be thrown.
        // *
        // * @param pattern the production pattern to check
        // *
        // * @throws ParserCreationException if the pattern referenced a
        // * pattern not added to this parser
        //

        private void CheckPattern(ProductionPattern pattern)
        {
            for (int i = 0; i <= pattern.Count - 1; i++)
            {
                CheckAlternative(pattern.Name, pattern[i]);
            }
        }
        //*
        // * Calculates the look-aheads needed for the specified pattern
        // * alternative. This method attempts to resolve any conflicts in
        // * optional elements by recalculating look-aheads for referenced
        // * productions.
        // *
        // * @param alt the production pattern alternative
        // * @param pos the pattern element position
        // *
        // * @throws ParserCreationException if the look-ahead set couldn't
        // * be determined due to inherent ambiguities
        //

        private void CalculateLookAhead(ProductionPatternAlternative alt, int pos)
        {
            ProductionPattern        pattern   = default(ProductionPattern);
            ProductionPatternElement elem      = default(ProductionPatternElement);
            LookAheadSet             first     = default(LookAheadSet);
            LookAheadSet             follow    = default(LookAheadSet);
            LookAheadSet             conflicts = default(LookAheadSet);
            LookAheadSet             previous  = new LookAheadSet(0);
            string location = null;
            int    length   = 1;

            // Check trivial cases
            if (pos >= alt.Count)
            {
                return;
            }

            // Check for non-optional element
            pattern = alt.Pattern;
            elem    = alt[pos];
            if (elem.MinCount == elem.MaxCount)
            {
                CalculateLookAhead(alt, pos + 1);
                return;
            }

            // Calculate simple look-aheads
            first  = FindLookAhead(elem, 1, new CallStack(), null);
            follow = FindLookAhead(alt, 1, pos + 1, new CallStack(), null);

            // Resolve conflicts
            location  = "at position " + (pos + 1);
            conflicts = FindConflicts(pattern.Name, location, first, follow);
            while (conflicts.Size() > 0)
            {
                length += 1;
                conflicts.AddAll(previous);
                first          = FindLookAhead(elem, length, new CallStack(), conflicts);
                follow         = FindLookAhead(alt, length, pos + 1, new CallStack(), conflicts);
                first          = first.CreateCombination(follow);
                elem.LookAhead = first;
                if (first.Intersects(conflicts))
                {
                    first = first.CreateIntersection(conflicts);
                    ThrowAmbiguityException(pattern.Name, location, first);
                }
                previous  = conflicts;
                conflicts = FindConflicts(pattern.Name, location, first, follow);
            }

            // Check remaining elements
            CalculateLookAhead(alt, pos + 1);
        }
        //*
        // * 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));
            }
        }
Пример #4
0
        //*
        // * Adds a new production pattern to the parser. The first pattern
        // * added is assumed to be the starting point in the grammar. The
        // * patterns added may be validated to some extent.
        // *
        // * @param pattern the pattern to add
        // *
        // * @throws ParserCreationException if the pattern couldn't be
        // * added correctly to the parser
        //

        public virtual void AddPattern(ProductionPattern pattern)
        {
            if (pattern.Count <= 0)
            {
                throw new ParserCreationException(ParserCreationException.ErrorType.INVALID_PRODUCTION, pattern.Name, "no production alternatives are present (must have at " + "least one)");
            }
            if (patternIds.ContainsKey(pattern.Id))
            {
                throw new ParserCreationException(ParserCreationException.ErrorType.INVALID_PRODUCTION, pattern.Name, "another pattern with the same id (" + pattern.Id + ") has already been added");
            }
            patterns.Add(pattern);
            patternIds.Add(pattern.Id, pattern);
            SetInitialized(false);
        }
        //*
        // * Adds a new production pattern to the parser. The pattern
        // * will be added last in the list. The first pattern added is
        // * assumed to be the starting point in the grammar. The
        // * pattern will be validated against the grammar type to some
        // * extent.
        // *
        // * @param pattern the pattern to add
        // *
        // * @throws ParserCreationException if the pattern couldn't be
        // * added correctly to the parser
        //

        public override void AddPattern(ProductionPattern pattern)
        {
            // Check for empty matches
            if (pattern.IsMatchingEmpty())
            {
                throw new ParserCreationException(ParserCreationException.ErrorType.INVALID_PRODUCTION, pattern.Name, "zero elements can be matched (minimum is one)");
            }

            // Check for left-recusive patterns
            if (pattern.IsLeftRecursive())
            {
                throw new ParserCreationException(ParserCreationException.ErrorType.INVALID_PRODUCTION, pattern.Name, "left recursive patterns are not allowed");
            }

            // Add pattern
            base.AddPattern(pattern);
        }
Пример #6
0
        //*
        // * Returns a string representation of a production pattern.
        // *
        // * @param prod the production pattern
        // *
        // * @return a detailed string representation of the pattern
        //

        private string ToString(ProductionPattern prod)
        {
            StringBuilder buffer = new StringBuilder();
            StringBuilder indent = new StringBuilder();
            LookAheadSet  @set   = default(LookAheadSet);
            int           i      = 0;

            buffer.Append(prod.Name);
            buffer.Append(" (");
            buffer.Append(prod.Id);
            buffer.Append(") ");
            for (i = 0; i <= buffer.Length - 1; i++)
            {
                indent.Append(" ");
            }
            buffer.Append("= ");
            indent.Append("| ");
            for (i = 0; i <= prod.Count - 1; i++)
            {
                if (i > 0)
                {
                    buffer.Append(indent);
                }
                buffer.Append(ToString(prod[i]));
                buffer.Append("" + Convert.ToChar(10) + "");
            }
            for (i = 0; i <= prod.Count - 1; i++)
            {
                @set = prod[i].LookAhead;
                if (@set.GetMaxLength() > 1)
                {
                    buffer.Append("Using ");
                    buffer.Append(@set.GetMaxLength());
                    buffer.Append(" token look-ahead for alternative ");
                    buffer.Append(i + 1);
                    buffer.Append(": ");
                    buffer.Append(@set.ToString(m_tokenizer));
                    buffer.Append("" + Convert.ToChar(10) + "");
                }
            }
            return(buffer.ToString());
        }
        //*
        // * Parses a production pattern. A parse tree node may or may
        // * not be created depending on the analyzer callbacks.
        // *
        // * @param pattern the production pattern to parse
        // *
        // * @return the parse tree node created, or null
        // *
        // * @throws ParseException if the input couldn't be parsed
        // * correctly
        //

        private Node ParsePattern(ProductionPattern pattern)
        {
            ProductionPatternAlternative alt        = default(ProductionPatternAlternative);
            ProductionPatternAlternative defaultAlt = default(ProductionPatternAlternative);

            defaultAlt = pattern.DefaultAlternative;
            for (int i = 0; i <= pattern.Count - 1; i++)
            {
                alt = pattern[i];
                if (!object.ReferenceEquals(defaultAlt, alt) && IsNext(alt))
                {
                    return(ParseAlternative(alt));
                }
            }
            if (defaultAlt == null || !IsNext(defaultAlt))
            {
                ThrowParseException(FindUnion(pattern));
            }
            return(ParseAlternative(defaultAlt));
        }
        //*
        // * Returns a look-ahead set with all conflics between
        // * alternatives in a production pattern.
        // *
        // * @param pattern the production pattern
        // * @param maxLength the maximum token sequence length
        // *
        // * @return a look-ahead set with the conflicts found
        // *
        // * @throws ParserCreationException if an inherent ambiguity was
        // * found among the look-ahead sets
        //

        private LookAheadSet FindConflicts(ProductionPattern pattern, int maxLength)
        {
            LookAheadSet result = new LookAheadSet(maxLength);
            LookAheadSet set1   = default(LookAheadSet);
            LookAheadSet set2   = default(LookAheadSet);

            for (int i = 0; i <= pattern.Count - 1; i++)
            {
                set1 = pattern[i].LookAhead;
                for (int j = 0; j <= i - 1; j++)
                {
                    set2 = pattern[j].LookAhead;
                    result.AddAll(set1.CreateIntersection(set2));
                }
            }
            if (result.IsRepetitive())
            {
                ThrowAmbiguityException(pattern.Name, null, result);
            }
            return(result);
        }
        //*
        // * Returns the union of all alternative look-ahead sets in a
        // * production pattern.
        // *
        // * @param pattern the production pattern
        // *
        // * @return a unified look-ahead set
        //

        private LookAheadSet FindUnion(ProductionPattern pattern)
        {
            LookAheadSet result = default(LookAheadSet);
            int          length = 0;
            int          i      = 0;

            for (i = 0; i <= pattern.Count - 1; i++)
            {
                result = pattern[i].LookAhead;
                if (result.GetMaxLength() > length)
                {
                    length = result.GetMaxLength();
                }
            }
            result = new LookAheadSet(length);
            for (i = 0; i <= pattern.Count - 1; i++)
            {
                result.AddAll(pattern[i].LookAhead);
            }

            return(result);
        }
        //*
        // * Finds the look-ahead set for a production pattern element. The
        // * maximum look-ahead length must be specified. This method does
        // * NOT take the element repeat into consideration when creating
        // * the look-ahead set. It is also possible to specify a look-ahead
        // * set filter, which will make sure that unnecessary token
        // * sequences will be avoided.
        // *
        // * @param elem the production pattern element
        // * @param length the maximum look-ahead length
        // * @param dummy a parameter to distinguish the method
        // * @param stack the call stack used for loop detection
        // * @param filter the look-ahead set filter
        // *
        // * @return the look-ahead set for the pattern element
        // *
        // * @throws ParserCreationException if an infinite loop was found
        // * in the grammar
        //

        private LookAheadSet FindLookAhead(ProductionPatternElement elem, int length, int dummy, CallStack stack, LookAheadSet filter)
        {
            LookAheadSet      result  = default(LookAheadSet);
            ProductionPattern pattern = default(ProductionPattern);

            if (elem.IsToken())
            {
                result = new LookAheadSet(length);
                result.Add(elem.Id);
            }
            else
            {
                pattern = GetPattern(elem.Id);
                result  = FindLookAhead(pattern, length, stack, filter);
                if (stack.Contains(pattern.Name))
                {
                    result = result.CreateRepetitive();
                }
            }

            return(result);
        }
        //*
        // * Finds the look-ahead set for a production pattern. The maximum
        // * look-ahead length must be specified. It is also possible to
        // * specify a look-ahead set filter, which will make sure that
        // * unnecessary token sequences will be avoided.
        // *
        // * @param pattern the production pattern
        // * @param length the maximum look-ahead length
        // * @param stack the call stack used for loop detection
        // * @param filter the look-ahead set filter
        // *
        // * @return the look-ahead set for the production pattern
        // *
        // * @throws ParserCreationException if an infinite loop was found
        // * in the grammar
        //

        private LookAheadSet FindLookAhead(ProductionPattern pattern, int length, CallStack stack, LookAheadSet filter)
        {
            LookAheadSet result = default(LookAheadSet);
            LookAheadSet temp   = default(LookAheadSet);

            // Check for infinite loop
            if (stack.Contains(pattern.Name, length))
            {
                throw new ParserCreationException(ParserCreationException.ErrorType.INFINITE_LOOP, pattern.Name, (string)null);
            }

            // Find pattern look-ahead
            stack.Push(pattern.Name, length);
            result = new LookAheadSet(length);
            for (int i = 0; i <= pattern.Count - 1; i++)
            {
                temp = FindLookAhead(pattern[i], length, 0, stack, filter);
                result.AddAll(temp);
            }
            stack.Pop();

            return(result);
        }
        //*
        // * Changes the production pattern containing this alternative.
        // * This method should only be called by the production pattern
        // * class.
        // *
        // * @param pattern the new production pattern
        //

        internal void SetPattern(ProductionPattern pattern)
        {
            this.m_pattern = pattern;
        }
        //*
        // * Calculates the look-ahead needed for the specified production
        // * pattern. This method attempts to resolve any conflicts and
        // * stores the results in the pattern look-ahead object.
        // *
        // * @param pattern the production pattern
        // *
        // * @throws ParserCreationException if the look-ahead set couldn't
        // * be determined due to inherent ambiguities
        //

        private void CalculateLookAhead(ProductionPattern pattern)
        {
            ProductionPatternAlternative alt = default(ProductionPatternAlternative);
            LookAheadSet result = default(LookAheadSet);

            LookAheadSet[] alternatives = null;
            LookAheadSet   conflicts    = default(LookAheadSet);
            LookAheadSet   previous     = new LookAheadSet(0);
            int            length       = 1;
            int            i            = 0;
            CallStack      stack        = new CallStack();

            // Calculate simple look-ahead
            stack.Push(pattern.Name, 1);
            result       = new LookAheadSet(1);
            alternatives = new LookAheadSet[pattern.Count];
            for (i = 0; i <= pattern.Count - 1; i++)
            {
                alt             = pattern[i];
                alternatives[i] = FindLookAhead(alt, 1, 0, stack, null);
                alt.LookAhead   = alternatives[i];
                result.AddAll(alternatives[i]);
            }
            if (pattern.LookAhead == null)
            {
                pattern.LookAhead = result;
            }
            conflicts = FindConflicts(pattern, 1);

            // Resolve conflicts
            while (conflicts.Size() > 0)
            {
                length += 1;
                stack.Clear();
                stack.Push(pattern.Name, length);
                conflicts.AddAll(previous);
                for (i = 0; i <= pattern.Count - 1; i++)
                {
                    alt = pattern[i];
                    if (alternatives[i].Intersects(conflicts))
                    {
                        alternatives[i] = FindLookAhead(alt, length, 0, stack, conflicts);
                        alt.LookAhead   = alternatives[i];
                    }
                    if (alternatives[i].Intersects(conflicts))
                    {
                        if (pattern.DefaultAlternative == null)
                        {
                            pattern.DefaultAlternative = alt;
                        }
                        else if (!object.ReferenceEquals(pattern.DefaultAlternative, alt))
                        {
                            result = alternatives[i].CreateIntersection(conflicts);
                            ThrowAmbiguityException(pattern.Name, null, result);
                        }
                    }
                }
                previous  = conflicts;
                conflicts = FindConflicts(pattern, length);
            }
            for (i = 0; i <= pattern.Count - 1; i++)
            {
                // Resolve conflicts inside rules
                CalculateLookAhead(pattern[i], 0);
            }
        }
Пример #14
0
        ///<summary>Initializes the parser by creating all the production
        ///patterns.</summary>
        ///
        ///<exception cref='ParserCreationException'>if the parser
        ///couldn't be initialized correctly</exception>
        private void CreatePatterns()
        {
            ProductionPattern            pattern = default(ProductionPattern);
            ProductionPatternAlternative alt     = default(ProductionPatternAlternative);

            pattern = new ProductionPattern((int)ExpressionConstants.EXPRESSION, "Expression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.XOR_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.XOR_EXPRESSION, "XorExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.OR_EXPRESSION, 1, 1);
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_1, 0, -1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.OR_EXPRESSION, "OrExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.AND_EXPRESSION, 1, 1);
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_2, 0, -1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.AND_EXPRESSION, "AndExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.NOT_EXPRESSION, 1, 1);
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_3, 0, -1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.NOT_EXPRESSION, "NotExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.NOT, 0, 1);
            alt.AddProduction((int)ExpressionConstants.IN_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.IN_EXPRESSION, "InExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.COMPARE_EXPRESSION, 1, 1);
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_4, 0, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.IN_TARGET_EXPRESSION, "InTargetExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.FIELD_PROPERTY_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.IN_LIST_TARGET_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.IN_LIST_TARGET_EXPRESSION, "InListTargetExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.LEFT_PAREN, 1, 1);
            alt.AddProduction((int)ExpressionConstants.ARGUMENT_LIST, 1, 1);
            alt.AddToken((int)ExpressionConstants.RIGHT_PAREN, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.COMPARE_EXPRESSION, "CompareExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.SHIFT_EXPRESSION, 1, 1);
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_6, 0, -1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.SHIFT_EXPRESSION, "ShiftExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.ADDITIVE_EXPRESSION, 1, 1);
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_8, 0, -1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.ADDITIVE_EXPRESSION, "AdditiveExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.MULTIPLICATIVE_EXPRESSION, 1, 1);
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_10, 0, -1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.MULTIPLICATIVE_EXPRESSION, "MultiplicativeExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.POWER_EXPRESSION, 1, 1);
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_12, 0, -1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.POWER_EXPRESSION, "PowerExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.NEGATE_EXPRESSION, 1, 1);
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_13, 0, -1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.NEGATE_EXPRESSION, "NegateExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.SUB, 0, 1);
            alt.AddProduction((int)ExpressionConstants.MEMBER_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.MEMBER_EXPRESSION, "MemberExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.BASIC_EXPRESSION, 1, 1);
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_14, 0, -1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.MEMBER_ACCESS_EXPRESSION, "MemberAccessExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.DOT, 1, 1);
            alt.AddProduction((int)ExpressionConstants.MEMBER_FUNCTION_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.BASIC_EXPRESSION, "BasicExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.LITERAL_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.EXPRESSION_GROUP, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.MEMBER_FUNCTION_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.SPECIAL_FUNCTION_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.MEMBER_FUNCTION_EXPRESSION, "MemberFunctionExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.FIELD_PROPERTY_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.FUNCTION_CALL_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.FIELD_PROPERTY_EXPRESSION, "FieldPropertyExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.IDENTIFIER, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.SPECIAL_FUNCTION_EXPRESSION, "SpecialFunctionExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.IF_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.CAST_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.IF_EXPRESSION, "IfExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.IF, 1, 1);
            alt.AddToken((int)ExpressionConstants.LEFT_PAREN, 1, 1);
            alt.AddProduction((int)ExpressionConstants.EXPRESSION, 1, 1);
            alt.AddToken((int)ExpressionConstants.ARGUMENT_SEPARATOR, 1, 1);
            alt.AddProduction((int)ExpressionConstants.EXPRESSION, 1, 1);
            alt.AddToken((int)ExpressionConstants.ARGUMENT_SEPARATOR, 1, 1);
            alt.AddProduction((int)ExpressionConstants.EXPRESSION, 1, 1);
            alt.AddToken((int)ExpressionConstants.RIGHT_PAREN, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.CAST_EXPRESSION, "CastExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.CAST, 1, 1);
            alt.AddToken((int)ExpressionConstants.LEFT_PAREN, 1, 1);
            alt.AddProduction((int)ExpressionConstants.EXPRESSION, 1, 1);
            alt.AddToken((int)ExpressionConstants.ARGUMENT_SEPARATOR, 1, 1);
            alt.AddProduction((int)ExpressionConstants.CAST_TYPE_EXPRESSION, 1, 1);
            alt.AddToken((int)ExpressionConstants.RIGHT_PAREN, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.CAST_TYPE_EXPRESSION, "CastTypeExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.IDENTIFIER, 1, 1);
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_15, 0, -1);
            alt.AddToken((int)ExpressionConstants.ARRAY_BRACES, 0, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.INDEX_EXPRESSION, "IndexExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.LEFT_BRACE, 1, 1);
            alt.AddProduction((int)ExpressionConstants.ARGUMENT_LIST, 1, 1);
            alt.AddToken((int)ExpressionConstants.RIGHT_BRACE, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.FUNCTION_CALL_EXPRESSION, "FunctionCallExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.IDENTIFIER, 1, 1);
            alt.AddToken((int)ExpressionConstants.LEFT_PAREN, 1, 1);
            alt.AddProduction((int)ExpressionConstants.ARGUMENT_LIST, 0, 1);
            alt.AddToken((int)ExpressionConstants.RIGHT_PAREN, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.ARGUMENT_LIST, "ArgumentList");
            alt     = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.EXPRESSION, 1, 1);
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_16, 0, -1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.LITERAL_EXPRESSION, "LiteralExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.INTEGER, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.REAL, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.STRING_LITERAL, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.BOOLEAN_LITERAL_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.HEX_LITERAL, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.CHAR_LITERAL, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.NULL_LITERAL, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.DATETIME, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.TIMESPAN, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.BOOLEAN_LITERAL_EXPRESSION, "BooleanLiteralExpression");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.TRUE, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.FALSE, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern = new ProductionPattern((int)ExpressionConstants.EXPRESSION_GROUP, "ExpressionGroup");
            alt     = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.LEFT_PAREN, 1, 1);
            alt.AddProduction((int)ExpressionConstants.EXPRESSION, 1, 1);
            alt.AddToken((int)ExpressionConstants.RIGHT_PAREN, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_1, "Subproduction1");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.XOR, 1, 1);
            alt.AddProduction((int)ExpressionConstants.OR_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_2, "Subproduction2");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.OR, 1, 1);
            alt.AddProduction((int)ExpressionConstants.AND_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_3, "Subproduction3");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.AND, 1, 1);
            alt.AddProduction((int)ExpressionConstants.NOT_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_4, "Subproduction4");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.IN, 1, 1);
            alt.AddProduction((int)ExpressionConstants.IN_TARGET_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_5, "Subproduction5");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.EQ, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.GT, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.LT, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.GTE, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.LTE, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.NE, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_6, "Subproduction6");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_5, 1, 1);
            alt.AddProduction((int)ExpressionConstants.SHIFT_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_7, "Subproduction7");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.LEFT_SHIFT, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.RIGHT_SHIFT, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_8, "Subproduction8");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_7, 1, 1);
            alt.AddProduction((int)ExpressionConstants.ADDITIVE_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_9, "Subproduction9");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.ADD, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.SUB, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_10, "Subproduction10");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_9, 1, 1);
            alt.AddProduction((int)ExpressionConstants.MULTIPLICATIVE_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_11, "Subproduction11");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.MUL, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.DIV, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.MOD, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_12, "Subproduction12");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)SynteticPatterns.SUBPRODUCTION_11, 1, 1);
            alt.AddProduction((int)ExpressionConstants.POWER_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_13, "Subproduction13");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.POWER, 1, 1);
            alt.AddProduction((int)ExpressionConstants.NEGATE_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_14, "Subproduction14");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.MEMBER_ACCESS_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            alt = new ProductionPatternAlternative();
            alt.AddProduction((int)ExpressionConstants.INDEX_EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_15, "Subproduction15");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.DOT, 1, 1);
            alt.AddToken((int)ExpressionConstants.IDENTIFIER, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);

            pattern           = new ProductionPattern((int)SynteticPatterns.SUBPRODUCTION_16, "Subproduction16");
            pattern.Synthetic = true;
            alt = new ProductionPatternAlternative();
            alt.AddToken((int)ExpressionConstants.ARGUMENT_SEPARATOR, 1, 1);
            alt.AddProduction((int)ExpressionConstants.EXPRESSION, 1, 1);
            pattern.AddAlternative(alt);
            AddPattern(pattern);
        }
Пример #15
0
        //*
        // * Creates a new production node.
        // *
        // * @param pattern the production pattern
        //

        public Production(ProductionPattern pattern)
        {
            this.m_pattern = pattern;
            this.children  = new ArrayList();
        }