Terminal and nonterminal symbols

From Wikipedia, the free encyclopedia

In computer science, terminal and nonterminal symbols are those symbols that are used to construct production rules in a formal grammar. Whereas terminal symbols form the parts of strings generated by the grammar, nonterminal symbols map to the names of productions in the grammar, and generate strings by substitution either of other nonterminals or of terminals (or some combination of these).

For instance, to represent a (possibly signed) integer, the following (expressed in a variant of BNF) may be described:

<integer> ::= ['-'] <digit> {<digit>}
<digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'

Here, the symbols (-,0,1,2,3,4,5,6,7,8,9) are the terminal symbols and <digit> and <integer> are the nonterminal symbols.