private MemoEntry applyRule(String rule, int position, int line) throws TreeException, ParserException {
	printMessage("applyRule: " + rule, position, line);
	MemoEntry m = recall(rule, position, line);
	if (m == null) {
	    /*
	     * "Create a new LR and push it onto the rule invocation stack."
	     * 
	     * At this point we found a rule which was never processed at this position. We
	     * start completely virgin here...
	     */
	    LR lr = new LR(MemoEntry.failed(), rule, null);
	    ruleInvocationStack = new RuleInvocation(MemoEntry.failed(), rule, null, ruleInvocationStack);
	    /*
	     * "Memoize lr, then evaluate R."
	     * 
	     * Put a fail into memoization memory and evaluate the rule afterwards.
	     */
	    m = MemoEntry.create(lr);
	    memo.setMemo(rule, position, line, m);
	    final MemoEntry ans = eval(rule, position, line);
	    /*
	     * "Pop lr off the rule invocation stack."
	     * 
	     * The evaluation of this lr is finished now and we can remove it from stack.
	     * This was needed in cases a left recursion whould be found within the rule.
	     */
	    ruleInvocationStack = ruleInvocationStack.getNext();

	    if ((m.getAnswer() instanceof LR) && (((LR) m.getAnswer()).getHead() != null)) {
		/*
		 * If a head was added to lr, we found a recursion during evaluation. We need to
		 * set the seed and process with left recursion evaluation. For that purpose we
		 * grow m with ans as seed.
		 */
		lr = (LR) m.getAnswer();
		lr.setSeed(ans);
		MemoEntry lrAnswer = lrAnswer(rule, position, line, m);
		printMessage("grow LR for '" + rule + "' (" + lrAnswer + ").", position, line);
		return lrAnswer;
	    } else {
		/*
		 * We finished an evaluation and did not find a recursion. So the result
		 * (independent of the the state) is stored in memo and returned.
		 */
		m.set(ans);
		printMessage("applied '" + rule + "' (" + ans.getAnswer() + ").", position, line);
		return ans;
	    }
	} else {
	    /*
	     * We were here already and with the same production. We either have a real
	     * answer or we found a recursion with or without currently seed growing...
	     */
	    if ((m.getAnswer() instanceof LR)) {
		/*
		 * There is still a LR object in the memo, so we found a recursion or an
		 * in-progress seed grow. We setup the LR seed grow and return the current seed.
		 */
		setupLR(rule, (LR) m.getAnswer());
		MemoEntry seed = ((LR) m.getAnswer()).getSeed();
		printMessage("Found recursion or grow in process for '" + rule + "' (" + seed + ").", position, line);
		return seed;
	    } else {
		/*
		 * We were already here and we have a real result. So we can just return the
		 * answer.
		 */
		printMessage("already processed '" + rule + "' (" + m + ").", position, line);
		return m;
	    }
	}
    }
private MemoEntry applyRule ( String rule , int position , int line ) throws TreeException , ParserException { printMessage ( "applyRule: " + rule , position , line ) ; MemoEntry m = recall ( rule , position , line ) ; if ( m == null ) { LR lr = new LR ( MemoEntry . failed ( ) , rule , null ) ; ruleInvocationStack = new RuleInvocation ( MemoEntry . failed ( ) , rule , null , ruleInvocationStack ) ; m = MemoEntry . create ( lr ) ; memo . setMemo ( rule , position , line , m ) ; final MemoEntry ans = eval ( rule , position , line ) ; ruleInvocationStack = ruleInvocationStack . getNext ( ) ; if ( ( m . getAnswer ( ) instanceof LR ) && ( ( ( LR ) m . getAnswer ( ) ) . getHead ( ) != null ) ) { lr = ( LR ) m . getAnswer ( ) ; lr . setSeed ( ans ) ; MemoEntry lrAnswer = lrAnswer ( rule , position , line , m ) ; printMessage ( "grow LR for '" + rule + "' (" + lrAnswer + ")." , position , line ) ; return lrAnswer ; } else { m . set ( ans ) ; printMessage ( "applied '" + rule + "' (" + ans . getAnswer ( ) + ")." , position , line ) ; return ans ; } } else { if ( ( m . getAnswer ( ) instanceof LR ) ) { setupLR ( rule , ( LR ) m . getAnswer ( ) ) ; MemoEntry seed = ( ( LR ) m . getAnswer ( ) ) . getSeed ( ) ; printMessage ( "Found recursion or grow in process for '" + rule + "' (" + seed + ")." , position , line ) ; return seed ; } else { printMessage ( "already processed '" + rule + "' (" + m + ")." , position , line ) ; return m ; } } }
This method tries to apply a production at a given position. The production
is given as a name and not as a concrete rule to process all choices
afterwards.

@param rule
@param position
@return
@throws TreeException
@throws ParserException