STEP Programming Example 3:

What follows is an admittedly complex example of a single STEP program that computes factorial.  Understanding this document is probably a good “final test” of your knowledge of STEP at this point, although you needn't understand STEP to this extent to complete many of the projects.  A SNAFU representation of the program would be:

SNAFU:
let STOP = 5 in
let START = 1 in
let COUNTER = level_trigger(not(equals(STOP,LTE)),cond(isnil(LTE),START,add(1,LTE))) in
level_trigger(not(equals(STOP,COUNTER)),cond(isnil(LTE),1,multiply(COUNTER,LTE)))

STEP:
<?xml version="1.0"?>
<stepgraph id="graph1">
<trigger id="blocker">
  <exp id="m" opcode="sxe.core.equals">
      <splice id="trig_factorial_read" target="trig_factorial"/>
      <value id="vid"><snobject type="snbench/integer">24</snobject></value>
  </exp>
    <level_trigger id="trig_factorial">
        <exp id="not" opcode="sxe.core.not">
            <exp id="equals" opcode="sxe.core.equals">
                <splice id="ptr_stop" target="stop_value"/>
                <splice id="tr1" target="trig_counter_read"/>
            </exp>
        </exp>
        <exp id="cond" opcode="sxe.core.cond">
            <exp id="isnil1" opcode="sxe.core.isnil">
                <last_trigger_eval id="lte_fact" target="trig_factorial"/>
            </exp>
            <value id="1">
                <snobject type="snbench/integer">1</snobject>
            </value>
            <exp id="multiply" opcode="sxe.core.math.multiply">
                <last_trigger_eval id="blah" target="trig_factorial"/>
                <read opcode="block" id="trig_counter_read" target="trig_counter">
                    <level_trigger id="trig_counter">
                        <exp id="not_" opcode="sxe.core.not">
                            <exp id="equals_" opcode="sxe.core.equals">
                                <value id="stop_value">
                                    <snobject type="snbench/integer">5</snobject>
                                </value>
                                <last_trigger_eval id="lte" target="trig_counter"/>
                            </exp>
                        </exp>
                        <exp id="cond2" opcode="sxe.core.cond">
                            <exp id="isnil" opcode="sxe.core.isnil">
                                <last_trigger_eval id="lte1" target="trig_counter"/>
                            </exp>
                            <value id="start_value">
                                <snobject type="snbench/integer">1</snobject>
                            </value>
                            <exp id="add" opcode="sxe.core.math.add">
                                <last_trigger_eval id="lte2" target="trig_counter"/>
                                <value id="val1">
                                    <snobject type="snbench/integer">1</snobject>
                                </value>
                            </exp>
                        </exp>
                    </level_trigger>
                </read>
            </exp>
        </exp>
    </level_trigger>
</trigger>
</stepgraph>

Finally, a graphical representation of the STEP is included (click the link to see the full image):


Michael Ocean (mocean@cs.bu.edu)
Creation Date: 1/10/06
Last Change: 1/12/06