next up previous contents index
Next: 3.4 Lists Up: 3 Tutorial Previous: 3.2 Expressions

3.3 Statements

external

Statements   form in general the simple part of an abstract syntax. Again (as for precedence in expressions), problems such as ``dangling else'' do not belong to the abstract syntax word. And again some choices must be made. This is the case for optional parts. The typical case is those of an if statement in which the else part is optional. A first attempt can be:

ifthen : Exp #	 Statement -> Statement;
ifthenelse: Exp # Statement # Statement -> Statement;

One can want to have a unique operator to unify the two cases. But this means that (if we have to write the semantics after that) we can give a semantics to the null statement.

if : Exp # Statement # Opt_Statement -> Statement;
null_statement : -> Null_Statement;
Opt_Statement = Statement + Null_Statement;

The more natural solution uses lists of statements, with the possibility to have an empty list of statements.

if : Exp # Statement_s # Statement_s -> Statement;
statement_s : Statement* -> Statement;

The notations ``P*'' and ``P+'' where P is the name of a phyla read as ``list of P''. In the first case the list can be empty, while the second case indicates a non empty list.

In this example, the ``then'' part of the if-statement can be an empty list. Again, one may have to make a choice between a strict abstract syntax introducing a phylum for non-empty lists of statements, and a more permissive one.

external Lists, Definition of Operators

external


next up previous contents index
Next: 3.4 Lists Up: 3 Tutorial Previous: 3.2 Expressions

Thierry Despeyroux
Fri May 16 15:24:06 MET DST 1997