Give a regular grammar for L Give a regular grammar for $L = \{a^n b^n : n \leqslant 100\}$
I would do something like this :
$S \to A \ |\ \text{empty string}$
$A \to aB \ |\  \text{empty string}$
$B \to Ab$
but How do we keep count of the number in the grammar? meaning How does it know when there are more that $100$ $a$'s. Also I'm not even sure if my way makes sense.
Any help would be appreciated. 
 A: Hint: Use non-terminals as memory.  In particular (and this envisions a right regular grammar) for each $n$ let $A_n$ be a nonterminal which means that (so far) $n$ $\mathtt{a}$'s have been written to the string, and let $B_n$ be a nonterminal which means that $n$ more $\mathtt{b}$'s need to be written to the string.
A: Notice that the type of grammar you are considering is not regular as it is "left and right regular", so it is actually a linear grammar.
Nevertheless, you do not need a linear grammar, as $L$ is regular and moreover it is finite.So, from Pumping Lemma, as the longest word you have to recognize has lenght 200, you can conclude that the minimal automaton recognizing $L$ has at lest 201 states, so you cannot expect a "small" grammar.
This is a simple one ($S$ is the axioms, $A_1$, $\ldots$, $A_{100}$, $B_1$, $\ldots$, $B_{100}$ are non-terminals), it is a right regular grammar:
$S \to aA_1 \ |\  \varepsilon$
$A_1 \to aA_2 \ |\  b$
$A_2 \to aA_3 \ |\  bB_2$
$\ldots$
$A_{99} \to aA_{100} \ |\  bB_{99}$
$A_{100} \to bB_{100}$
$B_{100} \to bB_{99}$
$B_{99} \to bB_{98}$
$\ldots$
$B_{3} \to bB_{2}$
$B_{2} \to b$
Try to imagine the automaton described by this grammar (non-terminals are states, you need also an extra state, say $B_1$, which will be the final state).
