Friday, October 28, 2016

The simplest parser

It is a parser  in which the text has already been separated out between operators and tokens Separating out token and operators,  that part has always been the battle, but when that is done what is left?

# Expression are simple when the text has been tokenized
# so lets do that
tokop = [('a',','),('b','.')]

for i in tokop.len() :
if tokop[i][1] == '.' :  parent = parent.pevious()
parent.append(tokop[i][0])

This code is collect tokens by block level, nothing more.  But it assumes that append maintains graph integrity, however the graph is stored.

Grammar is always block based, it is the decoding of all the syntax short cuts we use, and need. Dealing with that is simply painful.

The other point is that in a descend only graph, how do you find the previous parent?  Launch another operator from the top that stops when  the target is at the next block start, block counts work.  It is a direct shot when the child index is known because you can skip down by block count, Homing in with log n steps.  The site operator cannot let graph operations maintain stacks and jump up and down the graph, arbitrarily, that is a no no.


No comments: