statechart_fig1_redialer.xml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?xml version="1.0" ?>
  2. <statechart>
  3. <semantics
  4. big_step_maximality="syntactic"
  5. concurrency="many"
  6. orthogonal_priority="none"
  7. input_event_lifeline="whole"
  8. enabledness_memory_protocol="small_step"
  9. assignment_memory_protocol="small_step"/>
  10. <datamodel>
  11. import sccd.action_lang.lib.utils;
  12. c = 0;
  13. lp = 1234567890;
  14. p = 0;
  15. digit = func(i:int, pos:int) {
  16. result = i // 10**pos % 10;
  17. # print("digit " + int_to_str(pos) + " of " + int_to_str(i) + " is " + int_to_str(result));
  18. return result;
  19. };
  20. numdigits = func(i:int) {
  21. if (i == 0)
  22. return 0;
  23. return float_to_int(log10(i)) + 1;
  24. };
  25. </datamodel>
  26. <inport name="in">
  27. <event name="redial"/>
  28. </inport>
  29. <outport name="out">
  30. <event name="out"/>
  31. </outport>
  32. <root>
  33. <parallel id="Dialing">
  34. <state id="Dialer" initial="WaitForDial">
  35. <state id="WaitForDial" stable="true">
  36. <!-- t1 -->
  37. <transition event="dial(d:int), not redial" cond="c &lt; 10" target=".">
  38. <code>
  39. c += 1;
  40. lp = lp * 10 + d;
  41. </code>
  42. <raise port="out" event="out">
  43. <param expr="d"/>
  44. </raise>
  45. </transition>
  46. <!-- t2 -->
  47. <transition event="dial(d:int), redial" cond="c == 0" target="../DialDigits">
  48. <code>
  49. # print("got dial("+int_to_str(d)+")");
  50. lp = d;
  51. c = 1;
  52. </code>
  53. <raise port="out" event="out">
  54. <param expr="d"/>
  55. </raise>
  56. </transition>
  57. </state>
  58. <state id="DialDigits">
  59. <!-- t3 -->
  60. <transition event="dial(d:int)" cond="c &lt; 10" target=".">
  61. <code>
  62. # print("got dial("+int_to_str(d)+")");
  63. lp = lp * 10 + d;
  64. c += 1;
  65. </code>
  66. <raise port="out" event="out">
  67. <param expr="d"/>
  68. </raise>
  69. </transition>
  70. <!-- t4 -->
  71. <transition cond="c == 10" target="../WaitForDial"/>
  72. </state>
  73. </state>
  74. <state id="Redialer" initial="WaitForRedial">
  75. <state id="WaitForRedial" stable="true">
  76. <!-- t5 -->
  77. <transition event="redial" cond="c == 0" target="../RedialDigits">
  78. <code>
  79. p = lp;
  80. </code>
  81. <raise event="dial">
  82. <param expr="digit(lp, 0)"/>
  83. </raise>
  84. </transition>
  85. </state>
  86. <state id="RedialDigits">
  87. <!-- t6 -->
  88. <transition cond="c &lt; numdigits(p)" target=".">
  89. <raise event="dial">
  90. <param expr="digit(p, c)"/>
  91. </raise>
  92. </transition>
  93. <!-- t7 -->
  94. <transition cond="c == numdigits(p)" target="../WaitForRedial"/>
  95. </state>
  96. </state>
  97. </parallel>
  98. </root>
  99. </statechart>