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:25]
rajit [Selections]
language:controlflow [2022/05/13 08:45]
rajit
Line 11: Line 11:
 An example of the loop construct in ACT is shown below: An example of the loop construct in ACT is shown below:
  
-<code>+<code act>
 ( i : 10 : bool x[i..i]; ) ( i : 10 : bool x[i..i]; )
 </code> </code>
Line 20: Line 20:
 range ''0..9''. The body of the loop is the statement ''bool x[i..i];''. The effect of this statement is the same as range ''0..9''. The body of the loop is the statement ''bool x[i..i];''. The effect of this statement is the same as
  
-<code>+<code act>
 bool x[0..0]; bool x[0..0];
 bool x[1..1]; bool x[1..1];
Line 31: Line 31:
 is shown below: is shown below:
  
-<code>+<code act>
 register r[1..8]; register r[1..8];
 (i : 1..8 : r[i](in[i],out[i],control); ) (i : 1..8 : r[i](in[i],out[i],control); )
Line 48: Line 48:
 command language. command language.
  
-<code>+<code act>
 pint i; pint i;
 i=0; i=0;
Line 65: Line 65:
  
 In production rule bodies, the loop In production rule bodies, the loop
-<code>+<code act>
 (&i:3: x[i]) (&i:3: x[i])
 </code> </code>
 expands to expands to
-<code>+<code act>
 x[0] & x[1] & x[2] x[0] & x[1] & x[2]
 </code> </code>
Line 82: Line 82:
 syntax of a selection statement is: syntax of a selection statement is:
  
-<code>+<code act>
 [ boolean_expression -> body  [ boolean_expression -> body 
 [] boolean_expression -> body [] boolean_expression -> body
Line 95: Line 95:
 something special for register 0 as follows: something special for register 0 as follows:
  
-<code>+<code act>
 (i : 32 :  (i : 32 : 
-    [ i = 0 -> r0(in[i],out[i],control) +    [ i = 0 -> r0(in[i],out[i],control); 
-   [] else -> r[i](in[i],out[i],control)+   [] else -> r[i](in[i],out[i],control);
     ]     ]
 ) )
Line 110: Line 110:
 the operators less than, less than or equal to, greater than, greater the operators less than, less than or equal to, greater than, greater
 than or equal to, equal to, and not equal to respectively. 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 act>
 +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>
 +
 +