Shop OBEX P1 Docs P2 Docs Learn Events
Got an approach to flattening dynamic list data in spin? "[3,2,1,4..9,1*,20]" — Parallax Forums

Got an approach to flattening dynamic list data in spin? "[3,2,1,4..9,1*,20]"

UltraLazerUltraLazer Posts: 30
edited 2011-03-28 02:38 in Propeller 1
I am working on an application where I need to use a pointer 'flatten' (maybe expand?) a some ascii data that represents a dynamic list.

list instructions:

[ - begin the list
] - end the list
, - separate items
.. - denotes a range (min..max)
! - not (not element value, can act on ranges)
* - wild card digit (max value 255, can't act on ranges)

Given example ascii data = "[3,2,1,4..9,1*,20]", converted decimal values should be written to an array preserving the order in which the elements were originally placed in the data. The desired output array would look like:

List[0] := 3
List[1] := 2
List[2] := 1
List[3] := 4
List[4] := 5
List[5] := 6
List[6] := 7
...
List[18] := 19
List[19] := 20

Decoding the list data "[!1..20]" later on would clear the list : List[0..19] := 0

I have some aspects of the code working but each time I re-vamp a little section of code I end up getting the same kind of ugly pointer Bookmarks and nested case/lookdown structures I was trying to get rid of. Right now the pointer craws along the data looking for instructions and writing values to the List array as it goes, but often has to backtrack and start doing something diffrent if it encounters wild card digits and ranges...

I was wondering if any one could recommended a better approach or "comp-sci order of operations" that might make this task simpler.

Any help would be greatly appreciated, thanks!

Comments

Sign In or Register to comment.