Re: Executing code without generating stack machine code

gtoal@gtoal.com
30 Apr 2005 11:01:16 -0400

          From comp.compilers

Related articles
Executing code without generating stack machine code himanshu.garg@gmail.com (2005-04-26)
Re: Executing code without generating stack machine code carlos.smith@sympatico.ca (Carlos) (2005-04-30)
Re: Executing code without generating stack machine code gtoal@gtoal.com (2005-04-30)
| List of all articles for this month |

From: gtoal@gtoal.com
Newsgroups: comp.compilers
Date: 30 Apr 2005 11:01:16 -0400
Organization: http://groups.google.com
References: 05-04-060
Keywords: interpreter
Posted-Date: 30 Apr 2005 11:01:16 EDT

himanshu.garg@gmail.com wrote:
> Hello,
>
> I have seen hoc ( Kernighan & Pike ), PL0 ( Niklaus Wirth )
that
> are calculator programs.
>
> I was wondering if I could execute code from its tree
> representation without generating any intermediate code. At the least
> my language supports if/then/else, loops, procedures, goto's and
> expressions. This would allow me to avoid the extra stack machine
> processor code, required to run the intermediate code.


Simple interpreting of trees is not hard, but you might find it more
fun to try something like a threaded code interpreter, which can be
added to an AST quite easily by replacing the object type with a
pointer to the procedure which implements that object type. (I'm sure
C++ programmers will have a pretty way to do it, but it all boils down
to procedure pointers)


I wrote an example some years ago, which might help:
http://www.gtoal.com/software/ThreadedCode


regards


Graham


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.