human
I am working on the file "ANTLR4-Python/Earley-Parser/Earley-Parser.ipynb".
The first task is:
The class EarleyParser implements the parsing algorithm of Jay Earley.
The class maintains the following member variables:
- mGrammar is the grammar that is used to parse the given token string.
- mString is the list of tokens and literals that has to be parsed.
As a hack, the first element of this list in None.
   Therefore, mString[i] is the ith token.
- mStateList is a list of sets of Earley items.  If $n$ is the length of the given token string
  (excluding the first element None), then $Q_i = \texttt{mStateList}[i]$. 
  The idea is that the set $Q_i$ is the set of those Earley items that the parser could be in 
  when it has read the tokens mString[1], $\cdots$,  mString[n].  $Q_0$ is initialized as follows:
  $$ Q_0 = \bigl{\langle\hat{S} \rightarrow \bullet S, 0\rangle\bigr}. $$
The Earley items are interpreted as follows: If we have
$$ \langle C \rightarrow \alpha \bullet \beta, k\rangle \in Q_i, $$
then we know the following:
- After having read the tokens mString[:k+1] the parser tries to parse the variable $C$
  in the token string mString[k+1:].
- After having read the token string mString[k+1:i+1] the parser has already recognized $\alpha$
  and now needs to recognize $\beta$ in the token string mString[i+1:] in order to parse the variable $C$.
Can you write Python code for it?

=====
Write me a the Python code you requested?
assistant
#Here is the Python code you requested.

class EarleyParser():
    def __init__(self, grammar, TokenList):
        self.mGrammar   = grammar 
        self.mString    = [None] + TokenList  # dirty hack so mString[1] is first token
        self.mStateList = [set() for i in range(len(TokenList)+1)] 
        print('Grammar:\n')
        print(self.mGrammar)
        print(f'Input: {self.mString}\n')
        self.mStateList[0] = { self.mGrammar.startItem() }