IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Algorithm question: RPN/stack processing.
I'm probably re-inventing the wheel, but I'm currently writing a CGI script that returns web pages built from templating information. (An example of the template file is [link|http://yceran.org/static/staticpages.qf|here]* if you're curious.) The script itself is written in [link|http://unicon.sourceforge.net/|Icon], so things like strings, lists and tables are first-class datatypes and thus easy to use. There is extensive string manipulation available, too, for those who don't know anything about Icon.

One of the things I've determined I need in the template language is an RPN processor (a bit like that use in HP calculators) to enable some conditional control et al. I've got all sorts of options for implementing this, but I'm not happy with some aspect of most of them. Has anyone else ever implemented an RPN processor?

Wade.

* Argh! Your browser will probably try to render it as it has HTML in it. Grr. Just do a browse source if your browse does that. The mime type is correct, BTW; text/plain.

"All around me are nothing but fakes
Come with me on the biggest fake of all!"

Expand Edited by static Sept. 8, 2001, 06:12:14 AM EDT
New Re: Algorithm question: RPN/stack processing.
May be a dumb idea, but isn't Icon an interpreted language? Couldn't you just have an Icon expression there and compute it using your interpreter?
New It's not a dumb idea.
But Icon is not an interpreted language. It's a translated language (it has it's own runtime p-code interpreter). If it were an interpreted language, I probably would have done what you suggested, yes.

Actually, I sorta began to head down that way. It's straightforward to get a function pointer to any builtin operator at runtime and call it with whatever you like. I was going to do something like that for most of the operators. Among other things, it gives me access to functions like repl() which repeats a string a given number of times. My original extension of this idea would have had the code build a list of operations at parse time so when it got to expanding all the tokens, if it found a list where it expected a string, then it would do a simple loop through the list, calling function pointers and moving values around in a mechanical and conditional free way. Unfortunately, this approach requires some very creative algorithms at a few points to solve some data-hiding and edge-condition problems.

Wade.

"All around me are nothing but fakes
Come with me on the biggest fake of all!"

New Progress report. And a request.
I've got some code for everyone to scrutine. Given template files [link|http://yceran.org/static/staticpages.qf|here], [link|http://yceran.org/static/archived.qf|here] and [link|http://yceran.org/html.qf|here], and program [link|http://yceran.org/static/qompose.icn|thus], I now have a means to generate pages like [link|http://yceran.org/static/archived.html|this] and all it's linked pages :-) with a minimum of duplicated information, to wit, the common layout markup. (The CGI stuff I have yet to implement, but that won't be hard.)

I know I probably could have done something like this with things like Apache's SSI tokens, but what does everyone think?

Oh, and I just went for the fairly dumb approach to the RPN code. It seems to be plenty quick enough. There are a few Icon-ish quirks with it, but I'll note them in the documentation.

Wade.

"All around me are nothing but fakes
Come with me on the biggest fake of all!"

     Algorithm question: RPN/stack processing. - (static) - (3)
         Re: Algorithm question: RPN/stack processing. - (Arkadiy) - (1)
             It's not a dumb idea. - (static)
         Progress report. And a request. - (static)

You were a prophet from above, then you came and sucked my blood.
40 ms