Interpreter loop - best approach in Prolog?
- From: sbaker8688@xxxxxxx
- Date: Mon, 08 Oct 2007 11:37:36 -0700
A while back I developed a custom interpreted programming language,
written in another language (not Prolog). I would like to write it in
Prolog.
The stack is the "global state" of the program that must be maintained
as each line of code is executed. There will be an "interpreter loop"
that gets a line of input, and does something to the stack (pushes
something, pops something, etc). I see two basic approaches: 1)
either maintain the stack as a "global variable" using assert/retract,
or 2) pass the old stack into various predicates to obtain the new
stack.
I don't mind doing 2. My question is how to do this (if desirable, or
recommended) without creating issues for the Prolog execution stack
(not to be confused with the stack in the language I am
implementing). In other words, how do I run the loop (getting input,
processing it) without stacking up stack frames or activation records
or whatever you want to call them through recursion?
In fact, I suppose this could still be an issue even with assert/
retract. Either way you have an essentially endless loop reading and
processing input. How do Prologgers typically deal with these
issues? Through tail-recursion? Or perhaps some special predicate
that does looping without recursion?
Thanks.
.
- Follow-Ups:
- Re: Interpreter loop - best approach in Prolog?
- From: bart demoen
- Re: Interpreter loop - best approach in Prolog?
- From: Chip Eastham
- Re: Interpreter loop - best approach in Prolog?
- Prev by Date: Re: Planner, micro-planner, etc.
- Next by Date: Re: How to solve a problem with an infinite loop [beginners question]
- Previous by thread: Compiling with gnu-prolog???
- Next by thread: Re: Interpreter loop - best approach in Prolog?
- Index(es):
Relevant Pages
|
|