Skip to main content

Section 6.2 The Abstract Syntax of C0

C0 consists of statements and expression which we will introduce and discuss separately. A C0 program consists of a statement \(s\in\Stmt\text{.}\) Statements can be nested, i.e. one statement can contain several other statements. In the following, we will be exclusively interested in C0 programs in their abstract syntax. We will nevertheless use some elements concrete syntax (parentheses, braces, etc.) to make it easier to read them for us humans. Definition 6.2.1 defines the abstract syntax of C0 statements.

Definition 6.2.1. C0 Statement Language.

\begin{equation*} \begin{array}{rclll} \text{Category} \amp \amp \text{Abstract Syntax} \amp \text{Concrete Syntax} \amp \text{Description} \\ \hline \mathit{Stmt} \ni s \amp \syndef \amp \AAssign{l}{e} \amp \CAssign le \amp \text{Assignment} \\ \amp | \amp \ABlock{s_1,\dots,s_n} \amp \CBlock{s_1,\dots,s_n} \amp \text{Block} \\ \amp | \amp \AIf{e}{s_1}{s_2} \amp \CIf e{s_1}{s_2} \amp \text{If} \\ \amp | \amp \AWhile{e}{s} \amp \CWhile es \amp \text{Loop} \\ \amp | \amp \AAbort \amp \CAbort \amp \text{Abort} \\ \end{array} \end{equation*}

Some statements also contain expressions, such as the if-statement. Therefore, we now define the C0 expression language.

Definition 6.2.2. C0 Expression Language.

\begin{equation*} \begin{array}{rclll} \text{Category} \amp \amp \text{Abstract Syntax} \amp \text{Concrete Syntax} \amp \text{Description} \\ \hline \mathit{LExpr} \ni l \amp \syndef \amp \AVar x \amp x \amp \text{Variable} \\ \mathit{Expr} \ni e \amp \syndef \amp l \amp l \amp \text{L-Value} \\ \amp | \amp \AConst c \amp c \amp \text{Constant} \\ \amp | \amp \ABinary{o}{e_1}{e_2}\amp e_1\mathop{o} e_2 \amp \text{Binary Expr.} \\ \end{array} \end{equation*}

Example 6.2.3.

The following example shows a small C0 program with its concrete and abstract syntax and the corresponding abstract syntax tree.

  q = 0;
  r = x;
  while (y <= r) {
    r = r - y;
    q = q + 1;