(related to Part: Formal Languages)
Assume that we have a simple example grammar $G=(V,T,R,S)$ such that: * The set of variables $V=\{S\}$ consist only of the starting symbol. * The terminal symbols (alphabet) consists of the following four characters $T=\{a,b,(,)\}.$ * The grammar rules $R$ are: * $S\to \epsilon$ * $S\to a$ * $S\to b$ * $S\to SS$ * $S\to (S)$
We want to build an abstract syntax tree $\operatorname{AST}(\omega)$ of the string $\omega=()ab()$.
$$\begin{array}{l} S \end{array}$$
$$\begin{array}{ll} S &\to S\\ &\to S \end{array}$$
$$\begin{array}{lll} S &\to S&\to (\\ &&\to S\\ &&\to )\\ &\to S \end{array}$$
$$\begin{array}{lll} S &\to S&\to (\\ &&\to )\\ &\to S \end{array}$$
$$\begin{array}{lll} S &\to S&\to (\\ &&\to )\\ &\to S&\to S\\ &&\to S\\ \end{array}$$
$$\begin{array}{lll} S &\to S&\to (\\ &&\to )\\ &\to S&\to a\\ &&\to S\\ \end{array}$$
$$\begin{array}{llll} S &\to S&\to (\\ &&\to )\\ &\to S&\to a\\ &&\to S&\to S\\ &&&\to S\\ \end{array}$$
$$\begin{array}{llll} S &\to S&\to (\\ &&\to )\\ &\to S&\to a\\ &&\to S&\to b\\ &&&\to S\\ \end{array}$$
$$\begin{array}{lllll} S &\to S&\to (\\ &&\to )\\ &\to S&\to a\\ &&\to S&\to b\\ &&&\to S&\to(\\ &&&&\to S\\ &&&&\to)\\ \end{array}$$
$$\begin{array}{lllll} S &\to S&\to (\\ &&\to )\\ &\to S&\to a\\ &&\to S&\to b\\ &&&\to S&\to(\\ &&&&\to)\\ \end{array}$$
Please note that the grammar $G$ is ambiguous. We can produce the same string using another abstract syntax tree.
$$\begin{array}{llll} S &\to S&\to (\\ &&\to )\\ &\to S&\to S\\ &&\to S&\to (\\ &&&\to S\\ &&&\to )\\ \end{array}$$
$$\begin{array}{llll} S &\to S&\to (\\ &&\to )\\ &\to S&\to S&\to S\\ &&&\to S\\ &&\to S&\to (\\ &&&\to S\\ &&&\to )\\ \end{array}$$
$$\begin{array}{llll} S &\to S&\to (\\ &&\to )\\ &\to S&\to S&\to S\\ &&&\to S\\ &&\to S&\to (\\ &&&\to )\\ \end{array}$$
$$\begin{array}{llll} S &\to S&\to (\\ &&\to )\\ &\to S&\to S&\to a\\ &&&\to S\\ &&\to S&\to (\\ &&&\to )\\ \end{array}$$
$$\begin{array}{llll} S &\to S&\to (\\ &&\to )\\ &\to S&\to S&\to a\\ &&&\to b\\ &&\to S&\to (\\ &&&\to )\\ \end{array}$$
Please note that unambiguous grammars can have ambiguous rule productions. The criterion of unambiguity of grammars only means that all (even different) productions of the grammar of a given word lead to the same abstract syntax tree.