[REBOL] Re: coding the closing parentheses correctly
From: dougedmunds:gmai:l at: 1-May-2008 10:23
Thanks! I am a total noob as to parsing, so I will to get reading
up on it.
How flexible is parsing if I have alternative types of
containers (besides 'a', also 'z'), where an a can be in
in a or in z, and z can be in a or z, etc?
Here's an example :
String input:
[C, DE, [C, DE ],{C, DE, [C, DE], {C, DE}}]
That more closely approximates my situation: I am feeding a binary
string to REBOL. It has to be parsed from left to right. There are
lots of types, 2 of which are containers:
lists, the square brackets [ ]
and tuples, the curly brackets { } .
As a binary the input looks like this:
#{
6C000000046B0001436B000244456C000000026B0001436B000244456A68046B
0001436B000244456C000000026B0001436B000244456A68026B0001436B0002
44456A
}
The data-type/containers all start with '6'
68 -> tuple (container), followed by length
6C -> list (container), followed by length
6A -> null (used to show end of a 'proper' lists)
6B -> string, followed by length, followed by value
The datatypes use different number of bytes to represent
length: list - 4, tuple - 1, string - 2
Expansion of binary example:
#{
6C00000004
6B000143
6B00024445
6C00000002 6B000143 6B00024445 6A
6804
6B000143
6B00024445
6C00000002 6B000143 6B00024445 6A
6802
6B000143 6B00024445
6A
}
Details:
6C 00000004 (list of 4
6B 0001 43 first, a string, length 1, (value x43 = "C")
6B 0002 4445 second, a string, length 2 (value x4445 = "DE")
6C 00000002 third, a list of 2
6B 0001 43 first, a string
6B 0002 4445 second, a string
6A end list of 2
68 04 fourth, a tuple of 4
6B 0001 43 first, a string
6B 0002 4445 second, a string
6C 00000002 third, a list of 2
6B 0001 43 first, a string
6B 0002 4445 second, a string
6A end list of 2
68 02 fourth, a tuple of 2
6B 0001 43 first, a string
6B 0002 4445 second, a string
6A end main list of 4
Maxim Olivier-Adlhoch wrote: