Skip to main content

Left Linear Grammar

This is a bit of a detour. Previously, we defined regular grammar as,

AaBAaA \rightarrow aB \\ A \rightarrow a

Let's consider another kind of grammar,

ABaAaA \rightarrow Ba \\ A \rightarrow a

Because the target has non-terminal on the left side, this grammar is called the left linear grammar. The regular grammar is sometimes called the right linear grammar.

In this section, we need to prove that left linear grammar can yield regular languages.

Proof by automaton

The first proof is done by constructing an FN that tests the language of the left linear grammar. And because FN recognizes regular language, we can prove that left linear grammar generates regular language if there exists such FN.

The construction is done backwards. Let's first define the starting state, qsqs.

For all,

AaA \rightarrow a

We create state AA if there exists none. Then create an edge from qsqs to AA (please note that this is in a different direction).

Then, for,

ABbA \rightarrow Bb

We create an edge with label bb from BB to AA.

After the construction, we mark SS as the accept state.

This automaton will accept the language of the left linear grammar. And because FN yields regular language, the left linear grammar yields regular language.

Why this automaton accepts the language from left linear grammar? For right linear grammar, it is done by derivation- that every transition in the automaton means a derivation. For left linear grammar, it is done by induction.

If,

uvu \Rightarrow v

We say,

vuv \Leftarrow u

This operation from vv to uu is called induction.

If a sentence can be inducted to SS, then it is a sentence in the language.

Let's consider a induction sequence,

v0vivi+1vn1Sv_0 \Leftarrow \ldots \Leftarrow v_i \Leftarrow v_{i + 1} \Leftarrow \ldots \Leftarrow v_{n-1} \Leftarrow S

For a induction,

vivi+1v_i \Leftarrow v_{i + 1}

It can be mapped to the transition,

T(qi,i@v)=qi+1\mathcal{T}(q_i, i@v) = q_{i+1}

Because we mapped SS into accept state, we can prove that the automaton accepts all sentences generated by the left linear grammar.

Proof by Regularity Preservation under Reverse

Another approach to prove that left linear grammars generate regular languages is by transforming them into right linear grammars through a reversal process. Here's how the construction works:

  1. Reverse Productions: For each production in the left linear grammar GG , reverse the order of symbols on the right-hand side. Specifically:

    • A production of the form ABaA \rightarrow B a becomes AaBA \rightarrow a B .
    • A production of the form AaA \rightarrow a remains AaA \rightarrow a .
  2. Construct Right Linear Grammar: The resulting grammar GG' from the previous step is a right linear grammar because all productions now conform to the right linear form (non-terminal on the right end, if present).

  3. Language Relationship: The language generated by GG' , denoted L(G)\mathcal{L}(G') , is the reversal of the language generated by GG . That is, L(G)={wRwL(G)}\mathcal{L}(G') = \{ w^R \mid w \in \mathcal{L}(G) \} .

  4. Regularity Preservation: Since GG' is a right linear grammar, L(G)\mathcal{L}(G') is a regular language. Regular languages are closed under reversal, meaning that if L(G)\mathcal{L}(G') is regular, then L(G)\mathcal{L}(G) (being the reversal of L(G)\mathcal{L}(G') ) is also regular.

To prove that regular languages are closed under reversal, we can use the properties of regular expressions and structural induction. Here's the proof:

  1. Regular Languages and Regular Expressions:
    Every regular language L\mathcal{L} can be represented by a regular expression EE .

  2. Reversal of Regular Expressions:
    We define the reversal of a regular expression EE , denoted ERE^R , recursively as follows:

    • Base cases:
      • λR=λ\lambda^R = \lambda (reversal of the empty string is itself).
      • aR=aa^R = a for aΣa \in \Sigma (reversal of a single symbol is itself).
      • R=\emptyset^R = \emptyset (reversal of the empty language is itself).
    • Inductive cases:
      • Union: (E+F)R=ER+FR(E + F)^R = E^R + F^R .
      • Concatenation: (EF)R=FRER(EF)^R = F^R E^R (reversing the order of concatenation).
      • Kleene star: (E)R=(ER)(E^*)^R = (E^R)^* .
  3. Reversal Preserves Regularity:
    By structural induction on EE :

    • Base cases: λ\lambda , aa , and \emptyset are regular expressions, and their reversals are trivially regular.
    • Union: If EE and FF are regular, then ER+FRE^R + F^R is regular (union of regular languages is regular).
    • Concatenation: If EE and FF are regular, then FRERF^R E^R is regular (concatenation of regular languages is regular).
    • Kleene star: If EE is regular, then (ER)(E^R)^* is regular (Kleene star of a regular language is regular).
  4. Conclusion:
    The reversal of a regular expression ERE^R is also a regular expression. Therefore, the language LR={wRwL}\mathcal{L}^R = \{ w^R \mid w \in \mathcal{L} \} is regular.
    Hence, regular languages are closed under reversal.

In all, we can prove that left linear grammar is equivalent to right linear grammar, thus generates regular language.