Previous Up Next

3.9  Expressions

simple-expr::=value-path
    | constructor
    | constructor expr
    | immediate
    | ( expr )
    | { label = expr { ; label = expr } }
    | simple-expr . label
 
multiple-matching::=pattern-list -> expr
    | pattern-list => expr
 
pattern-list::=pattern { pattern }
expr::=simple-expr
    | simple-expr simple-expr { simple-expr }
    | fun multiple-matching
    | simple-expr where [ rec ] definition { and definition }
    | let [ rec ] definition { and definition } in expr
    | if expr then expr else expr
    | prefix-op expr
    | expr infix-op expr
    | expr or expr
    | not expr
    | expr when expr
    | expr whenot expr
    | merge expr expr expr
    | expr fby expr
    | pre expr
    | last ident
    | expr -> expr
    | run simple-expr { simple-expr }
    | await signal-pattern do expr
    | match expr with match-handlers end
    | reset expr every expr
    | automaton automaton-handlers end
    | present present-handlers end
 
match-handlers::=[ | ] pattern -> expr { | pattern -> expr }
 
present-handlers::=[ | ] signal-pattern -> expr { | signal-pattern -> expr }
 
automaton-handlers::=[ | ] automaton-handler { | automaton-handler }
 
automaton-handler::=constructor [ pattern ] -> expr transitions
 
transitions::=є
    | then state-expression
    | continue state-expression
    | transition { transition }
 
transition::=until signal-pattern then state-expression
    | until signal-pattern continue state-expression
    | unless signal-pattern then state-expression
    | unless signal-pattern continue state-expression

The precedence and associativity rules are the one of Objective Caml. For special Lucid Synchrone primitives, they are given below: higher precedences come first.

runleft
lastright
pre-
function applicationright
fbyleft
when, whenotleft
mergeleft
... let,...-
->right

3.9.1  Simple expressions

Constants

Expressions consisting in a constant evaluate to an infinite stream made of this constant.

Variables

Expressions consisting in a variable evaluate to the value bound to this variable in the current evaluation environment.

Parenthetised expressions

The expression ( expr ) has the same value than expr.

Function abstraction

A function abstraction has two forms:

fun pattern1 ... patternn -> expr

defines a combinatorial (or state-less) function. This means that expression expr must not contain any state constructions.

fun pattern1 ... patternn => expr

defines a sequential (or state-full) function.

Function application

The expression expr1 expr2 is an application. The expression expr1 must evaluate to a functional value which is applied to the value of expr2.

The expression expr1 expr2 ... exprn stands for (...(expr1 expr2) ... exprn). No evaluation order is specified.

When expr1 is a function imported from the host language Objective Caml and expr2 is a stream then expr1 expr2 stands for the point-wise application of expr1 to every element of expr2.

Local definitions

The let and let rec constructs bind variables locally. The expression

let definition1 and ... and definitionn in expr

defines values to be visible in expr.

Recursive definitions of variables are introduced by let rec:

let rec definition1 and ... and definitionn in expr

Reverse local definition

The language provides an alternate form of local definitions written in a reverse order and borrowed from Caml Light. In this way, functions may be defined is a way similar to Lustre. The expression:

simple-expr where [ rec ] definition1 and ... and definitionn

has the meaning of:

let [ rec ] definition1 and ... and definitionn in expr

3.9.2  Operators

The operators written infix-op in the grammar can appear in infix position (between two expressions). The operators written prefix-op in the grammar (section 3.9 can appear in prefix position (in front of an expression).

Classical operators provided by Objective Caml (from the Pervasives module) are imported. As for general scalar value imported from the host language, they become stream operators which are applied point-wisely to streams.

Delays

The expression pre expr is the delayed stream. expr must be a stream. The clock of the result is the clock of expr. The n-th value of the result is the n−1-th value of expr. Its value at the first instant is undefined.

The binary operator fby is the initialized delay operator. The first value of expr1 fby expr2 is the first value of expr1. Its n-th value is the n−1-th value of expr2.

Shared Memory

The expression last ident denotes a shared memory which contains the last computed value of ident.

Initialization

expr1 -> expr2 initializes a stream. The expri must be streams of the same type and on the same clock. It returns a stream with the same type and clock. The first value of the result is the first value of expr1. Then, the n-th value of the result is the n-th value of expr2.

Point-wise conditional

The expression if expr1 then expr2 else expr3 is the point-wise conditional. expr1 must be a boolean stream, expr2 and expr3 two streams of the same type. The type of the result is the type of expr2. The expressions expri must be on the same clock. The clock of the result is the clock of expr1. The conditional returns a stream such that its n-th value is the n-th value of expr2 if the n-th value of expr1 is true and the n-th value of expr3 otherwise.

Under-sampling

The expression expr1 when expr2 is the under-sampling operator. expr1 must be a stream and expr2, a clock made from a boolean stream. The type of the result is the type of expr1. The expressions expri must be on the same clock cl. The clock of the result is a sub-clock cl on expr2. This expression returns the sub-stream of expr1 defined for all instants where expr2 is defined and is true.

Over-sampling

The expression merge expr1 expr2 expr3 merges two complementary streams. expr1 must be a boolean stream, expr2 and expr3 two streams of the same type. The type of the result is the type of expr2. If expr1 is on clock cl, expr2 must be on clock cl on expr1 (expr2 must be present when expr1 is present and true) and expr3 must be on clock cl on not expr1. This expression returns a stream such that its n-th value is the n-th value of expr2 if the n-th value of expr1 is true and the n-th value of expr3 otherwise.

3.9.3  Control Structures

The constructions reset, match/with, reset and automaton are control-structures which combine equations and thus belong to the syntactic class of definitions (see section 3.10).

A derived form belonging to the syntactic class of expressions is also provided. The derived form is useful for textual programming whereas the original one is motivated by the graphical representation of dataflow programs. The derived form is only syntactic sugar for the original form.

Awaiting Signals

The expression await spat do expr awaits for the presence of a signal before executing the expression expr. This construction is a short-cut for the expression:

letautomaton
| Await -> do unless spat then Go(v)
| Go(v) -> do emit o = expr done
end in
o

provided o is a fresh name and v is the list of free variables from the signal pattern spat.

Pattern Matching

The expression match expr with pat1 -> expr1 || patn -> exprn end is a short-cut for the expression:

letmatch expr with
| pat1 -> do o = expr1 done
| patn -> do o = exprn done
end in
o

provided o is a fresh name.

Modular Reset

The expression reset expr1 every expr2 is a short-cut for let reset o = expr1 every expr2 in o, provided o is a fresh name.

Automata

The expression automaton state1 -> expr1 trans1 || staten -> exprn transn end is a short-cut for the expression:

letautomaton
| state1 -> do o = expr1 trans1
| staten -> do o = exprn transn
end in
o

provided o is a fresh name.

Testing the Presence

The expression present spat1 -> expr1 || spatn -> exprn end is a short-cut for the expression:

letpresent
| spat1 -> do o = expr1 done
| spatn -> do o = exprn done
end in
o

provided o is a fresh name.


Previous Up Next