Chains Library
Accessed by \usetikzlibrary{chains}
Description
Chains are sequences of nodes that are arranged in a row or a column and that are, typically, connected by edges. More generally, they can be used to position nodes of a branching network in a systematic manner. For the positioning of nodes in rows and columns you can also use matrices (see
Section 17 of pgfmanual.pdf) but chains can also be used to describe the connections between nodes that have already been connected using, say, matrices. Thus, it often makes sense to use matrices for the positioning of elements
and chains to describe the connections.
Example with Chains
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,% for the rectangle
chains,% provides the chains
scopes}% allows to replace \begin{scope} \end{scope} with {}
\begin{document}
\begin{tikzpicture}[
nonterminal/.style={
rectangle,
minimum size=6mm,
very thick,
draw=red!50!black!50,
top color=white, % a shading that is white at the top...
bottom color=red!50!black!20, % and something else at the bottom
font=\itshape
},
terminal/.style={
rectangle,minimum size=6mm,rounded corners=3mm,
very thick,draw=black!50,
top color=white,bottom color=black!20,
font=\ttfamily
},
node distance=5mm, every on chain/.style={join}, every join/.style={->}
]
{ [start chain]
\node [on chain,nonterminal] {unsigned integer};
\node [on chain,terminal] {.};
\node [on chain,terminal] {digit};
\node [on chain,terminal] {E};
{ [start branch=plus]
\node (plus) [terminal,on chain=going above right] {+};
}
{ [start branch=minus]
\node (minus) [terminal,on chain=going below right] {-};
}
\node [on chain, nonterminal, join=with chain/plus-end, join=with chain/minus-end] {unsigned integer};
}
\end{tikzpicture}
\end{document}

Example with Matrix and Chains
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,% for the rectangle
chains,% provides the chains
scopes}% allows to replace \begin{scope} \end{scope} with {}
\begin{document}
\begin{tikzpicture}[
nonterminal/.style={
rectangle,
minimum size=6mm,
very thick,
draw=red!50!black!50,
top color=white, % a shading that is white at the top...
bottom color=red!50!black!20, % and something else at the bottom
font=\itshape
},
terminal/.style={
rectangle,minimum size=6mm,rounded corners=3mm,
very thick,draw=black!50,
top color=white,bottom color=black!20,
font=\ttfamily
},
every on chain/.style={join}, every join/.style={->}
]
\matrix[column sep=4mm] {
% First row:
& & & & \node (plus) [terminal] {+};&\\
% Second row:
\node (ui1) [nonterminal] {unsigned integer};&
\node (dot) [terminal] {.}; &
\node (digit) [terminal] {digit}; &
\node (e) [terminal] {E}; &
& % space in between
\node (ui2) [nonterminal] {unsigned integer};\\
% Third row:
& & & & \node (minus)[terminal] {-};&\\
};
{ [start chain]
\chainin (ui1);
\chainin (dot);
\chainin (digit);
\chainin (e);
{ [start branch=plus]
\chainin (plus);
}
{ [start branch=minus]
\chainin (minus);
}
\chainin (ui2) [join=with chain/plus-end, join=with chain/minus-end];
}
\end{tikzpicture}
\end{document}

Chains with Labels
Some times one needs to add labes to the edges created by the chains library (it happened to me before). Although it is not supported natively by the library, you can do it by tweaking the library.
An example is:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,% for the rectangle
chains,% provides the chains
scopes}% allows to replace \begin{scope} \end{scope} with {}
\makeatletter
\def\tikz@lib@parse@join#1{%
\def\tikz@temp{#1}%
\ifx\tikz@temp\pgfutil@empty%
\tikz@lib@parse@join@by by \pgf@stop%
\else%
\pgfutil@in@{with }{#1}%
\ifpgfutil@in@% 'with [by] [label]'
\pgfutil@in@{by }{#1}%
\ifpgfutil@in@% 'with by [label]'
\pgfutil@in@{label }{#1}%
\ifpgfutil@in@% 'with by label'
\tikz@lib@parse@join@with@by@label#1\pgf@stop%
\else% 'with by'
\tikz@lib@parse@join@with@by#1\pgf@stop%
\fi%
\else% 'with [label]'
\pgfutil@in@{label }{#1}%
\ifpgfutil@in@% 'with label'
\tikz@lib@parse@join@with@label#1\pgf@stop%
\else% with
\tikz@lib@parse@join@with@by#1 by \pgf@stop%
\fi%
\fi%
\else% '[by] [label]'
\pgfutil@in@{by }{#1}%
\ifpgfutil@in@% 'by [label]'
\pgfutil@in@{label }{#1}%
\ifpgfutil@in@% 'by label'
\tikz@lib@parse@join@by@label#1\pgf@stop%
\else% 'by'
\tikz@lib@parse@join@by#1\pgf@stop%
\fi%
\else% '[label]'
\pgfutil@in@{label }{#1}%
\ifpgfutil@in@% 'label'
\tikz@lib@parse@join@label#1\pgf@stop%
\else%
\tikz@lib@parse@join@by#1 by \pgf@stop%
\fi%
\fi%
\fi%
\fi%
}
\def\tikz@lib@parse@join@with@by@label with #1 by #2 label #3\pgf@stop{%
\tikzset{after node path={(#1)edge[every join,#2]#3(\tikzchaincurrent)}}%
}
\def\tikz@lib@parse@join@with@label with #1 label #2\pgf@stop{%
\tikzset{after node path={(#1)edge[every join]#2(\tikzchaincurrent)}}%
}
\def\tikz@lib@parse@join@by@label by #1 label #2\pgf@stop{%
\tikzset{after node path={\ifx\tikzchainprevious\pgfutil@empty\else(\tikzchainprevious)edge[every join,#1]#2(\tikzchaincurrent)\fi}}%
}
\def\tikz@lib@parse@join@label label #1\pgf@stop{%
\tikzset{after node path={\ifx\tikzchainprevious\pgfutil@empty\else(\tikzchainprevious)edge[every join]#1(\tikzchaincurrent)\fi}}%
}
\makeatother
\begin{document}
\begin{tikzpicture}[
nonterminal/.style={
rectangle,
minimum size=6mm,
very thick,
draw=red!50!black!50,
top color=white, % a shading that is white at the top...
bottom color=red!50!black!20, % and something else at the bottom
font=\itshape
},
terminal/.style={
rectangle,minimum size=6mm,rounded corners=3mm,
very thick,draw=black!50,
top color=white,bottom color=black!20,
font=\ttfamily
},
every on chain/.style={join}, every join/.style={->}
]
\matrix[column sep=4mm] {
% First row:
& & & & \node (plus) [terminal] {+};&\\
% Second row:
\node (ui1) [nonterminal] {unsigned integer};&
\node (dot) [terminal] {.}; &
\node (digit) [terminal] {digit}; &
\node (e) [terminal] {E}; &
& % space in between
\node (ui2) [nonterminal] {unsigned integer};\\
% Third row:
& & & & \node (minus)[terminal] {-};&\\
};
{ [start chain]
\chainin (ui1);
\chainin (dot);
\chainin (digit);
\chainin (e);
{ [start branch=plus]
\chainin (plus) [join=label {node[above left]{a label}}];
}
{ [start branch=minus]
\chainin (minus);
}
\chainin (ui2) [join=with chain/plus-end label {node[above right] {plus label}}, join=with chain/minus-end by dashed label {node [below right]{minus label}}];
}
\end{tikzpicture}
\end{document}

Reference
pgfmanual.pdf, pp. 284 et sec. The examples are a simplified version of the Tutorial: Putting a Diagram in Chains, of pp. 60