i wrapped up an earley parser, “yaep”, into a k .so here: http://www.ivorykite.com/ear/ear.tgz
earley parsers are known for their tolerance of ambiguity (firsts match - like PEG) and of both left and right recursion. here’s the demo that ear.tgz includes:
$ LD_LIBRARY_PATH=/home/jack/q/l32 q k.k
KDB+ 3.4 2016.06.14 Copyright (C) 1993-2016 Kx Systems
l32/ 4()core 6936MB jack g50 127.0.1.1 NONEXPIRE
parsing k using an earley parser
“E:E;e|e e:nve|te| t:n|v v:tA|V n:t[E]|(E)|{E}|N”
" x y x yxZ xY x x yx x x y x xy x"
“N;;NN;NVN;NVNVN;NA;N[N];VAN;VAAN;{NVN}[N;N]”
(“N”;();“NN”;“VNN”;(“V”;“N”;“VNN”);“AN”;“NN”;(“AV”;“N”);((“A”;“AV”);“N”);((“{”;“VNN”);“NN”))
lexing, classing and parsing k
((“/”;(“/,”;(“\:”;“@”)));(“\,”;(“'”;(“<”;“,”;“<:”);“=:”)))
native grammar
"E: E ‘;’ e #E0(0 2)| e #E1(0);e: n v e #e0(1 0 2)| t e #e1(0 1)|#e2();t: n #t0(0)| v #t1(0);v: t ‘A’#v0(1 0)|‘V’#v1(0);n: t ‘[’ E ‘]’#n0(0 2)|‘(’ E ‘)’#n..
native output
(E1;(
e1;(t1;(
v0;6;(t0;(
n1;(E1;(
e1;(t1;(
v0;2;(t0;(
n3;1))));(e1;(
t1;(v0;4;(
t1;(v1;3))));,
e2)))))));(e1;(
t1;(v0;8;(
t0;(n3;7))));(
e0;(`v1..
q)