Interpreter loop - best approach in Prolog?



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.

.



Relevant Pages

  • Re: switch between functions
    ... 'A' can't be called and use a separate stack... ... prolog - allocates a new stack frame ... The total space used by allocation of variables on the stack depends on ... The prolog and epilog that the compiler generates are dependent on the ...
    (alt.lang.asm)
  • Re: ARMCODE object
    ... (the latter would avoid potential problems brought up below) ... If new prolog, can a Saturn-based calc ... A sysRPL program may expect a result on the stack, ...
    (comp.sys.hp48)
  • Re: Interpreter loop - best approach in Prolog?
    ... written in another language (not Prolog). ... The stack is the "global state" of the program that must be maintained ... creating an endless loop in Prolog is through the ... you might have to define repeat for yourself. ...
    (comp.lang.prolog)
  • Re: Prolog to WAM Register Allocation?
    ... > I'm currently studying how Prolog compiles its source into Warren ... > Abstract Machine code and I was wondering what kind of algorithm does ... > Prolog use to assign variables and constants to X and Y registers? ... The model is highly optimised, as you probably gather, so stack frames ...
    (comp.compilers)
  • Re: Is C99 the final C? (some suggestions)
    ... You mean vague terminologies like "stack"? ... wrap whatever "spawn" mechanism you have in your language (or use some ... >> and because of Java's bignum class, it meant that exposing a widening multiply ... >> you use to determine this is just related to examining the carry flag. ...
    (comp.lang.c)