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:langs:chp [2023/04/07 08:19]
rajit [Syntactic replication]
language:langs:chp [2023/04/09 19:26]
rajit [Conditional execution]
Line 86: Line 86:
  
 In the published literature, non-deterministic selections are usually written using a thin bar ''|'' rather than the thick bar ''[]''. However, this can create some ambiguities in parsing. For example, consider the statement ''[ a -> y:=b | c | d -> skip ]''. This can be parsed in a number of ways, and it is not clear which one was the intended option. In the published literature, non-deterministic selections are usually written using a thin bar ''|'' rather than the thick bar ''[]''. However, this can create some ambiguities in parsing. For example, consider the statement ''[ a -> y:=b | c | d -> skip ]''. This can be parsed in a number of ways, and it is not clear which one was the intended option.
 +
 +===== Arrays: dynamic v/s non-dynamic indices =====
 +
 +Suppose an array ''x'' has been declared as:
 +<code act>
 +int x[10];
 +</code>
 +
 +Now when ''x'' is accessed in CHP, it could be accessed with an array index that is a run-time constant, or an index that is computed at run-time. For example, the CHP program
 +<code act>
 +chp {
 +   ...
 +   x[0] := x[0] + 1;
 +   ...
 +}
 +</code>
 +uses ''x'' with a constant index. As opposed to this, the program
 +<code act>
 +chp {
 +   ...
 +   x[i] := x[i] + 1;
 +   ...
 +}
 +</code>
 +uses ''x'' with an index that is computed using the run-time value of ''i''. This second category of arrays are referred to as //dynamic arrays//---not because the array size is dynamic, but because the element of the array accessed depends on a value that is computed by the circuit. 
 +
  
 ===== Loops ===== ===== Loops =====
Line 286: Line 312:
 *[ C?c; [ ([] i : N : c = i -> I[i]?d) ]; O!d ] *[ C?c; [ ([] i : N : c = i -> I[i]?d) ]; O!d ]
 </code> </code>
-where ''N'' is the number of channels in the ''I'' array.+where ''N'' is the number of channels in the ''I'' array. This approach ensures that index for the array ''I[]'' is always a constant.
  
 ====== The chp-txt sublanguage ====== ====== The chp-txt sublanguage ======