ArticleslgStudy

science

Left recursion

Left recursion is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Left recursion rather than just read about it. In short: 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, 1 + 2 + 3 {\displaystyle 1+2+3} can be recognized as a sum because it can be broken into 1 + 2 {\displaystyle 1+2} , also a sum, and + 3 {\displa…

Left recursion — main illustration
Left recursion — illustration

Key takeaways

  • Left recursion belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Left recursion to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Left recursion from memory before moving on to harder problems.

Reference excerpt

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, 1 + 2 + 3 {\displaystyle 1+2+3} can be recognized as a sum because it can be broken into 1 + 2 {\displaystyle 1+2} , also a sum, and

+ 3 {\displaystyle {}+3} , 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 A {\displaystyle A} that can derive to a sentential form with itself as the leftmost symbol. Symbolically,

A ⇒ + A α {\displaystyle A\Rightarrow ^{+}A\alpha } , where ⇒ + {\displaystyle \Rightarrow ^{+}} indicates the operation of making one or more substitutions, and α {\displaystyle \alpha } 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

A → A α {\displaystyle A\to A\alpha }

where α {\displaystyle \alpha } is a sequence of nonterminals and terminals . For example, the rule

E x p r e s s i o n → E x p r e s s i o n + T e r m {\displaystyle {\mathit {Expression}}\to {\mathit {Expression}}+{\mathit {Term}}}

is directly left-recursive. A left-to-right recursive descent parser for this rule might look like

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

A 0 → β 0 A 1 α 0 {\displaystyle A_{0}\to \beta _{0}A_{1}\alpha _{0}}

A 1 → β 1 A 2 α 1 {\displaystyle A_{1}\to \beta _{1}A_{2}\alpha _{1}}

⋯ {\displaystyle \cdots }

A n → β n A 0 α n {\displaystyle A_{n}\to \beta _{n}A_{0}\alpha _{n}}

where β 0 , β 1 , … , β n {\displaystyle \beta _{0},\beta _{1},\ldots ,\beta _{n}} are sequences that can each yield the empty string, while α 0 , α 1 , … , α n {\displaystyle \alpha _{0},\alpha _{1},\ldots ,\alpha _{n}} may be any sequences of terminal and nonterminal symbols at all. Note that these sequences may be empty. The derivation

A 0 ⇒ β 0 A 1 α 0 ⇒ + A 1 α 0 ⇒ β 1 A 2 α 1 α 0 ⇒ + ⋯ ⇒ + A 0 α n … α 1 α 0 {\displaystyle A_{0}\Rightarrow \beta _{0}A_{1}\alpha _{0}\Rightarrow ^{+}A_{1}\alpha _{0}\Rightarrow \beta _{1}A_{2}\alpha _{1}\alpha _{0}\Rightarrow ^{+}\cdots \Rightarrow ^{+}A_{0}\alpha _{n}\dots \alpha _{1}\alpha _{0}}

… excerpt ends here. Continue reading the full article.

Illustrations

Left recursion: Right-recursive parsing of a double subtraction
Right-recursive parsing of a double subtraction

Worked examples

Example 1 — a first encounter with Left recursion

Start with the simplest possible case. Write down what Left recursion claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Left recursion before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Left recursion ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Left recursion

In research
Left recursion appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Left recursion in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Left recursion is common in secondary-school and first-year university syllabi. It links to neighbouring topics Control flow, Formal languages, Parsing, so understanding it makes those chapters shorter.
In everyday life
Look for Left recursion outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Left recursion” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Left recursion in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Left recursion means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Left recursion out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Left recursion in simple terms?

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, 1 + 2 + 3 {\displaystyle…

Why does Left recursion matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Left recursion?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Left recursion.

Tags

  • Control flow
  • Formal languages
  • Parsing
  • Recursion

Keep exploring