Polish Notation - writing p.k to parse and evaluate

couldn’t find anything on the wiki,…

i’d like to implement a language using kdb+.  as an example, how about polish notation?

from http://en.wikipedia.org/wiki/Polish_notation

The q expression 7*5-6 in Polish Notation is written *-5 6 7

so, given:

$cat eg.p
*-5 6 7

$q eg.p
jack@uv:~/o$ echo *-5 6 7 >eg.p
jack@uv:~/o$ q eg.p
KDB+ 3.1 2014.07.01 Copyright (C) 1993-2014 Kx Systems
l32/ 2()core 1177MB jack uv 127.0.1.1 NONEXPIRE 

Welcome to kdb+ 32bit edition
For support please see http://groups.google.com/d/forum/personal-kdbplus
Tutorials can be found at http://code.kx.com/wiki/Tutorials
To exit, type \
To remove this startup msg, edit q.q
k){0N!x y}
'p.k: No such file or directory
@
“p”
“*-5 6 7”
q))

what do i have to expose in p.k?  parse? eval?

ta, jack.

Write p.k and save it where q.k is located:

\d .p
e:{1" evaluating ",x}

Now in you can call this evaluator from command line or from q:
q myscript.p
Or
p)+ 1 2

Of course, yo need to write a proper evaluator.
This mechanism works only line by line.

Pe 03.08.2014 12:17, “Jack Andrews” <effbiae@gmail.com> a scris:

couldn’t find anything on the wiki,…

i’d like to implement a language using kdb+.  as an example, how about polish notation?

from http://en.wikipedia.org/wiki/Polish_notation

The q expression 7*5-6 in Polish Notation is written *-5 6 7

so, given:

$cat eg.p
*-5 6 7

$q eg.p
jack@uv:~/o$ echo *-5 6 7 >eg.p
jack@uv:~/o$ q eg.p
KDB+ 3.1 2014.07.01 Copyright (C) 1993-2014 Kx Systems
l32/ 2()core 1177MB jack uv 127.0.1.1 NONEXPIRE 

Welcome to kdb+ 32bit edition
For support please see http://groups.google.com/d/forum/personal-kdbplus
Tutorials can be found at http://code.kx.com/wiki/Tutorials
To exit, type \
To remove this startup msg, edit q.q
k){0N!x y}
'p.k: No such file or directory
@
“p”
“*-5 6 7”
q))

what do i have to expose in p.k?  parse? eval?

ta, jack.


Submitted via Google Groups

Thanks Felix,

I have implemented my first non-trivial* language in k :)

i’ve hacked an eval for REVERSE polish notation
  http://en.wikipedia.org/wiki/Reverse_Polish_notation

jack@uv:~/o$ q
KDB+ 3.1 2014.07.01 Copyright (C) 1993-2014 Kx Systems
l32/ 2()core 1177MB jack uv 127.0.1.1 NONEXPIRE 

q)k).p.e:{{$[102=@:y;(y .|:2#x),2_x;0N!y,x]}/x@&:~101=t:@:‘x:-5!’-4!x}
q)p)5 1 2+4*+3-
1 5
2 1 5
4 3 5
3 17
,14

ta, jack

*for me.  a god might do this in fewer characters.