|
|
|
|
|
by cloudkj
2409 days ago
|
|
Coincidentally, I just wrote a simple JSON parser the other day as a toy exercise. A simplified snippet of parsing code (handling only arrays) relevant to the discussion here would be something like: def parse(text):
stack = []
index = 0
result = None
while index < len(text):
char = text[index]
val = None
if char == '[':
stack.append([])
elif char == ']':
val = stack.pop()
index += 1
if val is not None:
if stack:
stack[-1].append(val)
else:
result = val
return result
Using the test utilities in the repo indicate that the parsing logic can handle arbitrarily nested arrays (e.g. up to the 5,000,000 max in the test script), bound by the limits of the heap.It seems like the main criticism here is against recursive implementations. Or am I missing something? |
|