6.2 The Abstract Syntax of C0

C0 consists of programs that contain statements which in turn can contain expressions. We will first consider programs and statements and then introduce expressions separately later. Note that C0 does not have functions. It is however not too hard to add them and it is a good exercise to work on that after having studied this chapter.

Statements can form lists which we then call programs. A program can be put into a block which then itself is a statement. This allows us to use lists of statements wherever a statement is required, for example in the consequence and alternative of an if-then-else. 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 and programs.

Definition 6.2.1: C0 Statement Language
Category Abstract Syntax Concrete Syntax Description
Sequence
Empty Program
Crash
Assignment
Block
If
While
Abort

Note that the empty program is denoted by the empty string . In most of the examples, we do not write down explicitly. Only in cases where we want to make explicit that we are talking about the empty program, we use . For example, we write the program as . Some statements, like the if statement, contain expressions, which we introduce in the following:

Definition 6.2.2: C0 Expression Language
Category Abstract Syntax Concrete Syntax Description
Variable
L-Value
Constant
Binary Expression
Operators
Arithmetic Operators
Comparison Operators
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;
}