# Finding a grammar for a context-sensitive language

I am looking for a context-sensitive grammar $G$ for the language $$L = \left\{w \in \left\{0,1\right\}^* | \; |w|_0 \geq |w|_1 \right\}$$ where $|w|_0$ means the amount of the terminal $0$ in the word $w$.

I know how to create a PDA for this by "remembering" the amout of $1$'s, but I do not know how to create a Grammar (respectively the production rules).

-

Since you can recognize the language with a PDA, it must be context-free, so we can do better than a context-sensitive grammar. Here’s a context-free grammar that should work; $S$ is the initial symbol, $\lambda$ is the empty string, $E$ is intended to generate words with an equal number of $0$’s and $1$’s, and $U$ is intended to generate words with more $0$’s than $1$’s.
\begin{align*} &S\to U\\ &U\to E0U\mid E0E\\ &E\to 0E1E\mid 1E0E\mid\lambda \end{align*}
(I don’t really need $U$: I could use $S$ instead.)
The basic idea is that there has to be at least one extra $0$; the second production generates it, possibly preceded by a string with an equal number of $0$’s and $1$’s; what follows it may but need not have excess $0$'s.