Re: Anyone with reverse polish notation experience?
- Posted by Elliott Sales de Andrade <quantum_analyst at hotmail.com> Mar 12, 2003
- 500 views
>From: Derek Parnell <ddparnell at bigpond.com> >Subject: Re: Anyone with reverse polish notation experience? > > >On Tue, 11 Mar 2003 23:31:18 +0000, Pete Lomax <petelomax at blueyonder.co.uk> >wrote: > >> >>I'm parsing (prefix) expressions and getting reverse polish notation >>out. The question I have is at the point of pushing a postfix operator >>on a stack, clearly *all* the necessary pre-calculations will have >>been done. Should be a no-brainer, but I'm doing it register-based >>rather than stack-based. >> >>I'm adamant about prefix; eg add(3,4) instead of 3+4 >> >>Maybe later I'll get my head round infix.... (Guess I could stomach a >>link which makes me confident enough to do both in v0.1, rather than >>as I am just trying to get it working...) >> >>My question at this point is: Has anyone a difficult prefix-only >>expression hard to parse; rpn which worked unexpectedly, and/or any >>pointers which may save me some time? >> >>Eg: add(add(3,4),add(5,6)); not: (3+4)+(5+6) >> >>Equally, does anyone have an expression they feel would be hard to >>express in prefix rather than infix notation? >> > >I guess this really an oxymoron as by its very nature, prefix notation is >simple to parse. And providing you have enough registers (or stack space) >any complex prefix expression is easy using a recursive algorithm. > >But in case you up to a neat expression (and much time to evaluate it), I >present ... > > >power(add(div(power(div(add(27,power(69,div(1,3))),2),div(1,3)),3) >,power(div(2,add(27,power(69,div(1,3)))),div(1,3))),30000) > >This should work out to a very large number that is almost an integer. > Assuming add(x, y) equals x + y; div(x, y) equals x / y; and power(x, y) equals x ^ y; that equals... 1.456616911969342313612567116226969533712140705732487890018328015e2725 which is, ahem, only slightly over the size of an atom... > >cheers, >Derek Parnell >