# Differences

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

 language:controlflow [2019/04/18 14:22]rajit language:controlflow [2022/07/17 08:07] (current)rajit [Loops] Both sides previous revision Previous revision 2022/07/17 08:07 rajit [Loops] 2022/07/17 08:06 rajit [Loops] 2022/05/13 08:45 rajit 2020/12/02 01:00 external edit2020/06/03 14:21 rajit [Recursion] 2020/06/03 14:21 rajit [Selections] 2019/04/18 14:25 rajit [Selections] 2019/04/18 14:25 rajit [Selections] 2019/04/18 14:22 rajit 2019/04/18 14:19 rajit created Next revision Previous revision 2022/07/17 08:07 rajit [Loops] 2022/07/17 08:06 rajit [Loops] 2022/05/13 08:45 rajit 2020/12/02 01:00 external edit2020/06/03 14:21 rajit [Recursion] 2020/06/03 14:21 rajit [Selections] 2019/04/18 14:25 rajit [Selections] 2019/04/18 14:25 rajit [Selections] 2019/04/18 14:22 rajit 2019/04/18 14:19 rajit created 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: - + ( i : 10 : bool x[i..i]; ) ( i : 10 : bool x[i..i]; ) 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 - + 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: - + 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. - + pint i; pint i; i=0; i=0; Line 65: Line 65: In production rule bodies, the loop In production rule bodies, the loop - + (&i:3: x[i]) (&i:3: x[i]) expands to expands to - + x[0] & x[1] & x[2] x[0] & x[1] & x[2] Line 75: Line 75: syntax). The ''&'' symbol separates the body of the loop that is syntax). The ''&'' symbol separates the body of the loop that is instantiated for different values of ''i''. instantiated for different values of ''i''. + + The syntactic replication construct is written as follows: + + (sym id : range : body ) + + The ''sym'' (symbol) might be empty. ''id'' is a variable that can be used in ''body'', and takes the range specified by ''range''. ''range'' can be either an integer-valued expression or ''start .. end'' to indicate a start and end index. The result of the replication is + + body(id set to lo) sym body(id set to lo+1) sym ... sym body(id set to hi) + + where ''lo'' is the starting index of the range, and ''hi'' is the ending index, and ''body(id set to x)'' means ''body'' with the value of ''x'' substituted by the constant ''id''. ===== Selections ===== ===== Selections ===== + + Conditional execution is supported by the selection statement. The + syntax of a selection statement is: + + + [ boolean_expression -> body + [] boolean_expression -> body + .. + ] + + 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: + + + (i : 32 : + [ i = 0 -> r0(in[i],out[i],control); + [] else -> r[i](in[i],out[i],control); + ] + ) + + + 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. + + + template + defproc tree (bool a[N]) + { + [ N = 1 -> leaf l(a[0]); + [] N > 1 -> tree t0(a[0..N/2-1]); + tree t1(a[N/2..N-1]); + ] + } + +