Exemplo n.º 1
0
        private static Nonterminal Reduce(ParserStack stack, RuleType rule)
        {
            // Create a language element array big enough to hold the LHS and RHS
            // arguments.
            //
            int parameterCount = 1 + rule.Rhs.Length;

            LanguageElement[] parameters = new LanguageElement[parameterCount];

            // Create the LHS nonterminal.
            //
            Nonterminal lhs = rule.Lhs.CreateNonterminal();

            parameters[0] = lhs;

            // Pop the RHS language elements off the stack.
            //
            for (int idx = 0; idx < rule.Rhs.Length; ++idx)
            {
                parameters[parameterCount - idx - 1] = stack.Pop().LanguageElement;
            }

            // Invoke the rule.
            //
            rule.Invoke(parameters);
            return(lhs);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a new <see cref="ParserStackItem"/> to the <see cref="ParserStack"/>.
 /// </summary>
 /// <param name="languageElement">The <see cref="LanguageElement"/> associated with this <see cref="ParserStackItem"/>.  When created by a shift action,
 /// contains the <see cref="Terminal"/> that triggered the action.  When created by a reduce action, contains a <see cref="Nonterminal"/>
 /// constructed by the <see cref="RuleType.Lhs"/> of the <see cref="RuleType"/> that triggered the action.</param>
 /// <param name="state">The <see cref="ParserState"/> that represents the current parsing state when the <see cref="ParserStackItem"/> is the topmost
 /// item on the <see cref="ParserStack"/>.</param>
 public void Push(LanguageElement languageElement, ParserState state)
 {
     Push(new ParserStackItem(languageElement, state));
 }