general parser for k

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 (first match – like PEG) and of both left and right recursion. here’s the demo that ear.tgz includes:

 

64bit RPN compiler in q

Adapted from 64-bit reverse polish JIT compiler

The call to execute the compiled expression is unimplemented as my personal edition of kdb+ is 32bit and don’t want to write the 32bit to long mode and back again hack.

$ q r.q
KDB+ 3.4 2016.06.14 Copyright (C) 1993-2016 Kx Systems
0x4889e548b8ffffffffffffff7f48b80100000000000000585b4801d8504889ecc3

 

64-bit reverse polish JIT compiler

Here’s a 64-bit JIT compiler for the RPN calculator.  Each expression entered in a REPL is compiled by cc() in-memory and then called with a single instruction in exe().

You can see 64-bit  overflow:

$ gcc r.c -o r
$ ./r
>9223372036854775807 1 +
-9223372036854775808

reverse polish calculator in gcc

gcc makes it possible to code this RPN interpreter more compactly than C89..C11

 

call functions on the run – x86_64

It doesn’t take much to call an x86_64 function by its address and an array of arguments.  The technique is useful for implementing interpreters or responding to remote procedure calls.  Supports 4 args, but can be completed by adding rcx, r8, r9.  Extend using XMM floating point registers.