\[ \newcommand{\tr}{\Rightarrow} \newcommand{\trs}{\tr^{\!\ast}} \newcommand{\rlnm}[1]{\mathsf{(#1)}} \newcommand{\rred}[1]{\xrightarrow{#1}} \newcommand{\rreds}[1]{\mathrel{\xrightarrow{#1}\!\!^*}} \newcommand{\cl}{\mathsf{Cl}} \newcommand{\pow}{\mathcal{P}} \newcommand{\matches}{\mathrel{\mathsf{matches}}} \newcommand{\kw}[1]{\mathsf{#1}} \newcommand{\andop}{\mathrel{\&\!\&}} \newcommand{\orop}{\mathrel{\|}} \newcommand{\ff}{\mathsf{false}} \newcommand{\tt}{\mathsf{true}} \newcommand{\abra}[1]{\langle #1 \rangle} \newcommand{\bnfnt}[1]{\abra{\small \textsf{#1}}} \newcommand{\llbracket}{[\![} \newcommand{\rrbracket}{]\!]} \newcommand{\first}{\mathsf{First}} \newcommand{\nullable}{\mathsf{Nullable}} \newcommand{\follow}{\mathsf{Follow}} \newcommand{\tm}[1]{\mathsf{#1}} \]

A Context Free Grammar (CFG) consists of four components:

  • An alphabet of terminal symbols, which we shall usually write as $\Sigma$ (capital letter sigma)
  • A finite, non-empty set of non-terminal symbols, disjoint from the terminals, which we shall usually write as $\mathcal{N}$ (caligraphic letter N)
  • A finite set of production rules, which we shall usually write as $\mathcal{R}$ (caligraphic letter R)
  • A designated non-terminal from $\mathcal{N}$, called the start symbol, which we will usually write as $S$.

A sentential form is just a sequence of terminals (from $\Sigma$) and nonterminals (from $\mathcal{N}$).

The production rules $\mathcal{R}$ of a CFG consisting of components \((\Sigma,\mathcal{N},\mathcal{R},S)\) each have shape:

\[X \longrightarrow \alpha\]

where $X$ is a nonterminal from $\mathcal{N}$ and $\alpha$ is a sentenial form over $\Sigma$ and $\mathcal{N}$.