Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
language:controlflow [2019/04/18 14:22]
rajit
language:controlflow [2020/12/02 01:00]
127.0.0.1 external edit
Line 78: Line 78:
  
 ===== Selections ===== ===== Selections =====
 +
 +Conditional execution is supported by the selection statement. The
 +syntax of a selection statement is:
 +
 +<code>
 +[ boolean_expression -> body 
 +[] boolean_expression -> body
 +..
 +]
 +</code>
 +The last Boolean expression in the conditional can be the keyword
 +''else'', which is short-hand for 'all other guards are false.'
 +
 +Any one body whose corresponding Boolean expression is true is
 +executed. For instance, we can create 32 registers with
 +something special for register 0 as follows:
 +
 +<code>
 +(i : 32 : 
 +    [ i = 0 -> r0(in[i],out[i],control);
 +   [] else -> r[i](in[i],out[i],control);
 +    ]
 +)
 +</code>
 +
 +Boolean expressions can be constructed from Boolean variables, the
 +constants ''true'' and ''false'', and the Boolean operators
 +''&'', ''|'', and ''~'' denoting the and, or, and negation
 +operations respectively.  Numeric expressions can be compared using
 +''<'', ''< ='', ''>'', ''>='', ''='', and ''!='' for
 +the operators less than, less than or equal to, greater than, greater
 +than or equal to, equal to, and not equal to respectively.
 +
 +===== Recursion =====
 +
 +Type definitions can be recursive. For instance, the following
 +definition can be used to create a tree structure.
 +
 +<code>
 +template<pint N>
 +defproc tree (bool a[N])
 +{
 +  [ N = 1 -> leaf l(a[0]);
 + [] N > 1 -> tree<N/2> t0(a[0..N/2-1]);
 +             tree<N-N/2> t1(a[N/2..N-1]);
 +  ]
 +}
 +</code>
 +