What is a grammar?

A grammar is a set of rules that specify a possibly infinite number of legal sentences in a language.

Each sentence is composed of one or more symbols.

A symbol is either "non-terminal" (can be replaced by zero or more other symbols) or "terminal" (cannot be replaced by other symbols).

A rule has a "left-hand-side" which is a non-terminal symbol, and a "right-hand-side" which is a sequence of zero or more symbols.

A rule specifies how to replace the non-terminal symbol on the left-hand-side with the sequence of symbols in the right-hand-side.

Example:

[1] expression ::= expression '+' term
[2] expression ::=                term
[3] term ::= term '*' factor
[4] term ::=          factor
[5] factor ::= literal
[6] factor ::= variable

End of example.

You can "generate" a sentence by starting with the non-terminal symbol 'expression' as follows:

expression

Use rule 1:

expression
|
expression '+' term

Use rule 2:

expression
|
expression '+' term
|
term

Use rule 3:

expression
|
expression '+' term
|
term
|
term '*' factor

Use rule 4:

expression
|
expression '+' term
|
term
|
term '*' factor
|
factor

Use rule 5:

expression
|
expression '+' term
|
term
|
term '*' factor
|
factor
|
literal

Use rule 6:

expression
|
expression '+' term
|
term
|
term '*' factor
|        |
factor   variable
|
literal

Use rule 4:

expression
|
expression '+' term
|              |
term           factor
|
term '*' factor
|        |
factor   variable
|
literal

Use rule 5:

expression
|
expression '+'     term
|                  |
term               factor
|                  |
term '*' factor    literal
|        |
factor   variable
|
literal

There are no more non-terminals left, so we have to stop here with the result:

literal * variable + literal