Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- See notes after code for info
- -------------------------------------
- RESTORE 'Label of DATA block to parse
- READ DW,DH
- DIM DAT(DW,DH)
- @PARSE
- READ DV
- IF DV==-2 'End parsing
- IF DV==-1 THEN X=0:Y=Y+1:GOTO @PARSE
- DAT(X,Y)=DV
- X=X+1
- GOTO @PARSE
- -------------------------------------
- -NOTES-
- DATA must be formed in acccordance to specific rules to be compliant with the parser.
- These rules are as follows:
- -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)
- -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
- -Every DATA statement in the block (with the exception of the first and last) must end in -1
- -The last DATA statement of the block must be "DATA -2"
- A well-formed DATA statement that is parser-compliant could look like this:
- @D0
- DATA 4,4
- DATA 0,1,0,0,-1
- DATA 0,0,0,0,-1
- DATA 0,0,0,1,-1
- DATA 1,1,1,1,-1
- DATA -2
- 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.
- 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