Advertisement
TheFastFish

[PTC] DATA-to-Array Parser

Jun 18th, 2014
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. See notes after code for info
  2. -------------------------------------
  3. RESTORE 'Label of DATA block to parse
  4. READ DW,DH
  5. DIM DAT(DW,DH)
  6.  
  7. @PARSE
  8. READ DV
  9. IF DV==-2 'End parsing
  10. IF DV==-1 THEN X=0:Y=Y+1:GOTO @PARSE
  11. DAT(X,Y)=DV
  12. X=X+1
  13. GOTO @PARSE
  14. -------------------------------------
  15. -NOTES-
  16. DATA must be formed in acccordance to specific rules to be compliant with the parser.
  17. These rules are as follows:
  18. -Each DATA statement must contain the same amount of values. Eg: if one DATA statement is 4 values and another is 6, then 2 extra values must be added to the 4-value line (and they should probably be null/default)
  19. -The first DATA statement in the block must be the width(how many values in each line) and height(how many lines long) of the DATA block
  20. -Every DATA statement in the block (with the exception of the first and last) must end in -1
  21. -The last DATA statement of the block must be "DATA -2"
  22.  
  23. A well-formed DATA statement that is parser-compliant could look like this:
  24. @D0
  25. DATA 4,4
  26. DATA 0,1,0,0,-1
  27. DATA 0,0,0,0,-1
  28. DATA 0,0,0,1,-1
  29. DATA 1,1,1,1,-1
  30. DATA -2
  31.  
  32. This DATA block would then be parsed into a 4x4 array in exactly the way it was written. The DATA 4,4 at the beginning, the -1s at the end of each line, and the DATA -2 at the end are not parsed; they are simply used by the parser like metadata, but are required as specified above. The -1s are used to tell the parser that it has reached the end of a line and to increment the array y pointer while subsequently resetting the array x pointer back to 0. Afterwards, the parser calls @GOTO PARSE and begins reading each line.
  33. The only DATA to be parsed are all the 1s and 0s in the middle.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement