In the formal language theory of computer science, left recursion is a special case of recursion where a string is recognized as part of a language by the fact that it decomposes into a string from that same language (on the left) and a suffix (on the right). For instance, can be recognized as a sum because it can be broken into , also a sum, and , a suitable suffix. In terms of context-free grammar, a nonterminal is left-recursive if the leftmost symbol in one of its productions is itself (in the case of direct left recursion) or can be made itself by some sequence of substitutions (in the case of indirect left recursion). Definition A grammar is left-recursive if and only if there exists a nonterminal symbol that can derive to a sentential form with itself as the leftmost symbol. Symbolically, , where indicates the operation of making one or more substitutions, and is any sequence of terminal and nonterminal symbols. Direct left recursion Direct left recursion occurs when the definition can be satisfied with only one substitution. It requires a rule of the form where is a sequence of nonterminals and terminals . For example, the rule is directly left-recursive. A left-to-right recursive descent parser for this rule might look like void Expression() { Expression(); match('+'); Term(); } and such code would fall into infinite recursion when executed. Indirect left recursion Indirect left recursion occurs when the definition of left recursion is satisfied via several substitutions. It entails a set of rules following the pattern where are sequences that can each yield the empty string, while may be any sequences of terminal and nonterminal symbols at all. Note that these sequences may be empty. The derivation then gives as leftmost in its final sentential form. Removing left recursion Left recursion often poses problems for parsers, either because it leads them into infinite recursion (as in the case of most top-down parsers) or because they expect rules in a normal form that forbids it (as in the case of many bottom-up parsers, including the CYK algorithm). Therefore, a grammar is often preprocessed to eliminate the left recursion. Removing direct left recursion The general algorithm to remove direct left recursion follows. Several improvements to this method have been made. For a left-recursive nonterminal , discard any rules of the form and consider those that remain: where: each is a