spacepaste

  1.  
  2. /*
  3. encoding
  4. https://codeabbey.github.io/heavy-data-1/msc-4-asm-manual-1973.pdf this pdf serves as insperation to the encoding syntax format using by the parser
  5. only word BEFORE the colon shall be recognised, the rest shall be counted as if it where a comment
  6. x shall count as 0 or 1
  7. */
  8. #P:
  9. 0P: r0:r1
  10. 1P: r2:r3
  11. 2P: r4:r5
  12. 3P: r6:r7
  13. 4P: r8:r9
  14. 5P: r10:r11
  15. 6P: r12:r13
  16. 7P: r14:r15
  17. RP:
  18. 000:0P
  19. 001:1P
  20. 010:2P
  21. 011:3P
  22. 100:4P
  23. 101:5P
  24. 110:6P
  25. 111:7P
  26. REG:
  27. 0000:r0
  28. 0001:r1
  29. 0010:r2
  30. 0011:r3
  31. 0100:r4
  32. 0101:r5
  33. 0110:r6
  34. 0111:r7
  35. 1000:r8
  36. 1001:r9
  37. 1010:r10
  38. 1011:r11
  39. 1100:r12
  40. 1101:r13
  41. 1110:r14
  42. 1111:r15
  43. xx:
  44. 00:ADD
  45. 01:SUB
  46. 10:LD
  47. 11:XCH
  48. xxxx:
  49. 0000:CLR
  50. 0001:CLC
  51. 0010:IAC
  52. 0011:CMC
  53. 0100:CMA
  54. 0101:RAL
  55. 0110:RAR
  56. 0111:TCC
  57. 1000:DAC
  58. 1001:TCS
  59. 1010:STC
  60. 1011:DAA
  61. 1100:KBP
  62. CN:
  63. //1xxx: invert all other jump conditions
  64. // [] represent a muli-match parse, in where the same string can be matched multiple times without terminating to next rule after a single match
  65. 0xx1: none //jump if test signal of 4004 is = 0
  66. [1xx1]: none //jump if test signal of 4004 is = 1
  67. [0x1x]: none //jump if carry bit = 1
  68. [1x1x]: none //jump if carry bit = 0
  69. [01xx]: none //jump if accumulator = 0
  70. [11xx]: none //jump if accumulator != 0
  71. OP:
  72. 0000:WRM
  73. 0001:WMP
  74. 0010:WRR
  75. 0011:WPM
  76. 0100:WR0
  77. 0101:WR1
  78. 0110:WR2
  79. 0111:WR3
  80. 1000:SBM
  81. 1001:RDM
  82. 1010:RDR
  83. 1011:ADM
  84. 1100:RD0
  85. 1101:RD1
  86. 1110:RD2
  87. 1111:RD3
  88. // /* consecutive sequence will be concated
  89. // * example:
  90. // * |DATA|DATA|
  91. // * assuming DATA is 4 bits long
  92. // * indicates DATA takes up 8 bits
  93. // */
  94. DATA:
  95. xxxx:DATA
  96. ADDR:
  97. xxxx:ADDR
  98. /*
  99. | does nothing and can act as a visual seperator to help visualize the structure of an encoding's binary layout *
  100. $...{} represents variable placement based action code
  101. both #num and $name can be used to reference the position of an action code
  102. ${name#num} represents a $name that occurs more than once in the same rule, where #num indicates the occurence number of $name to act upon
  103. can be concated via $ or # to specify multiple places where the following rule should be placed
  104. FIN: |0011|RP|0| $FIN$0011$0 { puts($$.name); } $RP{ puts($$.content); }
  105. FIN: |0011|RP|0| $FIN $0011 $0 { puts($$.name); } $RP{ puts($$.content); }
  106. FIN: |0011|RP|0| $FIN${0011#0}$0 { puts($$.name); } $RP{ puts($$.content); }
  107. FIN: |0011|RP|0| $FIN
  108. $
  109. {
  110. 0
  111. 0
  112. 1
  113. 1
  114. #
  115. 0
  116. }
  117. #
  118. 3
  119. { puts($$.name); } $RP{ puts($$.content); }
  120. FIN: |0011|RP|0| #0#1#3 { puts($$.name); } $RP{ puts($$.content); }
  121. FIN: |0011|RP|0| #0 #1 #3 { puts($$.name); } $RP{ puts($$.content); }
  122. FIN: |0011|RP|0| $FIN { puts($$.name); } $0011{ puts($$.name); } $RP{ puts($$.content); } $0{ puts($$.name); }
  123. FIN: |0011|RP|0| $FIN{ puts($$.name); } ${0011#0}{ puts($$.name); } $RP{ puts($$.content); } $0{ puts($$.name); }
  124. FIN: |0011|RP|0| #0{ puts($$.name); } #1{ puts($$.name); } #2{ puts($$.content); } #3{ puts($$.name); }
  125. FIN: |0011|RP|0| #0{ puts($$.name); } $0011{ puts($$.name); } $RP{ puts($$.content); } #3{ puts($$.name); }
  126. all of these are equivilant to
  127. FIN { puts($$.name); } : |0011 { puts($$.name); } |RP { puts($$.content); } |0 { puts($$.name); } |
  128. FIM: |0010|RP|0|DATA|DATA| ${DATA#0} {DATA1}
  129. ${DATA#1} {DATA2}
  130. ${DATA#0}$FIM {ECHO}
  131. is equivilant to
  132. FIM {ECHO}: |0010|RP|0|DATA {DATA1} {ECHO} |DATA {DATA2}|
  133. */
  134. FIN1: |0011|RP|0|
  135. $0011 {
  136. printf("a->contents = 0011, regexEngineb_bits = %s\n", regexEngineb_bits);
  137. puts("FIN1 ");
  138. }
  139. $RP {
  140. puts("RP ");
  141. }
  142. FIN2: |0011|RP|1|
  143. $0011 {
  144. printf("a->contents = 0011, regexEngineb_bits = %s\n", regexEngineb_bits);
  145. puts("FIN1 ");
  146. }
  147. $RP {
  148. puts("RP ");
  149. }
  150. JCN: |0001|CN |ADDR|ADDR|
  151. $0001 {
  152. printf("a->contents = 0001, regexEngineb_bits = %s\n", regexEngineb_bits);
  153. puts("JCN ");
  154. }
  155. $CN {
  156. puts("CN");
  157. }
  158. ${ADDR#0}
  159. ${ADDR#1} {
  160. printf("a->contents = xxxx, regexEngineb_bits = %s\n", regexEngineb_bits);
  161. }
  162.