python - Earley Parser Recursion -
does earley parser have expected problems simple cycles?
i've made own implementation, it's pretty similar one, readable , 150 lines total (and i, of course, didn't write it):
http://www.nightmare.com/rushing/python/earley.py
that 1 looks me, , works in provided test case, simple grammar
e : [[e,e],[ident]] doesn't seem work. should generate arbitrary number of "ident" tokens, assuming e starting non-terminal , ident terminal. grammar, , similar style grammar, missed parser.
is problem in earley algoritm (i don't think is), or problem in implementation; if it's implementation based, there (relatively) easy solution or algorithm need rebuilt?
yes, has expected problem groups of rules of kind:
x1 ::= x2
x2 ::= x3
...
xn ::= x1
in case algorithm may enter in infinite recursion loop, if not checking states you've added earley chart.
in case you've presented above must not enter in infinite loop, because expansions of rule e ::= e e limited input. check implementation here:
https://en.wikipedia.org/wiki/earley_parser#the_algorithm
i have used implementation, , works fine.
Comments
Post a Comment