PRS Conditional Rules - CAST to HAC Migration Guide
Description: CAST to HAC Migration Guide

Next: PRS Loop Expressions, Previous: PRS Loop Rules, Up: PRS

### 11.2 Conditional Rules

In CAST, conditional production rules could be written inside PRS bodies as follows:

         prs {
         [pred ->
           x -> y-
         ]
         }

If the predicate pred evaluates true during the unroll compile phase, then the body is processed, otherwise it is skipped. In HAC, the syntax remains unchanged apart from the syntax of PRS expressions in the predicate. HAC also allows an optional else clause in the conditional body:

         [pred ->
           x -> y-
         [] else ->
           z -> y-
         ]

where in CAST, one had to explicitly write the predicates complement in a separate conditional to achieve else-semantics.

In CAST and HAC, conditional PRS bodies could appear inside instance-level conditionals and loops, such as:

         [pred ->
           prs {
             ...
           }
         ]

Conditional bodies and loops in the PRS may be nested inside each other arbitrarily deep.

HAC conditionals also support sequential else-if constructs and else-clauses. For example,

         [ expr1 ->
         [] expr2 ->
         [] expr3 ->
         [] else ->
         ]

Only the first clause in the sequence with a true guard will be unrolled and expanded. If none are true, then all clauses are skipped. The `else` clause is optional.