5 Translation of Oz Programs to Oz Core Programs

Oz programs are translated to Oz core programs by repeatedly applying the rules given in this chapter to subtrees of the parse tree, replacing the subtree with the result of the rule. A rule consists of the following:

A set of nonterminals.

The rule is only applicable to subtrees generated by a rule of one of these nonterminals.

A left-hand side.

The rule is only applicable if the subtree's structure matches the left-hand side pattern. Additionally, variables are introduced. Some parts may be left out (replaced by an ellipsis) if they reappear unmodified in the output.

A right-hand side.

When the rule is applied to a subtree, the latter is replaced by the subtree specified by the right-hand side. This may contain variables written as X, Y, or Z not appearing in the left-hand side: These variables are supposed to be fresh such that no capturing can occur.

Optionally, a side condition.

The rule is only applicable if the side-condition is satisfied.

Meta Variables

Inside rewrite rules, we use meta variables for terminals and phrases generated by nonterminals as shown in the following table:

Meta Variables

Corresponding Terminals and Nonterminals

x, x1, ..., xn

<variable>

D

<declaration part>

S

<statement>

E, E1, ..., Ek, En

<expression>

SE

<statement> or <expression>

P, P1, ..., Pk, Pn

<pattern>

EP, EP1, ..., EPn

<expression> or <pattern>

C, C1, ..., Cn

<case statement clause> or <case expression clause>

L, L1, ..., Ln

<cond statement clause> or <cond expression clause> or <dis statement clause>

l

<label>

f1, ..., fn

<feature>

s1, ..., sn

<subtree> or <subpattern>

Core Variables

The result of the transformation may have references to so-called Core variables. We indicate this by writing them in backquotes; they are not bound lexically, but are looked up in static environment. Examples are `List.toRecord` and `RaiseDebugCheck`. If the print name of a Core variable contains a dot, then it is supposed to be looked up (without the backquotes) in the Base Environment (see ``The Oz Base Environment'').

Errors

When no rule is applicable and the program is not an Oz Core program, we speak of a syntax error. Such a program is not a valid Oz program.



Martin Henz and Leif Kornstaedt
Version 1.4.0 (20080702)