Re: Implementing a stack-based interpreter



cvrebert@xxxxxxxxx wrote:

> I know this is comp.compilers, but since there isn't a
> comp.interpreters, I figure this is the right place to ask.
> I'm trying write an interpreter for a programming language but haven't
> been able to find anything on how to write a stack-based interpreter.
> If anyone could point me to a book/website I'd be much obliged.

> [Compile to a string of reverse polish operators, then interpret that string
> pushing results on the stack and popping operands off the stack. -John]

Yes.

Many of the needed techniques are the same, so many compiler books
should also be useful to interpreter writers.

Most interpreters do at least a little bit of compiling.

The usual BASIC interpreter compiled each line, mostly by converting
keywords to a single byte, and sometimes converting numeric constants
to internal form. That is done to each line as it is typed in.

Also, it is very unusual for compilers to compile everything down to
machine code. Most use subroutine calls for I/O and more complicated
mathematical operations. On machines without hardware multiply and
divide, those are done by subroutine call.

Also, formatted output (printf() and Fortran's FORMAT) usually involves
interpreting the format strings.

-- glen
.



Relevant Pages

  • Re: BB4WFORTH - Making it more compatible....
    ... but using the string found ... When the interpreter runs out of data (i.e>IN is greater than the ... COMPILE, and POSTPONE are usually used by the system for constructing basic definitions. ...
    (comp.lang.forth)
  • Re: Creating an operating system
    ... If your interpreter uses some intermediate representation of the line ... Another option is to compile on-the-fly to an instruction format - ... faster execution on subsequent passes. ... I can imagine this being done for a language, ...
    (comp.programming)
  • Re: Creating an operating system
    ... If your interpreter uses some intermediate representation of the line ... Another option is to compile on-the-fly to an instruction format - ... faster execution on subsequent passes. ... I can imagine this being done for a language, ...
    (comp.os.linux.development.system)
  • Re: IEEE-FP 0.5.3
    ... used to generate NaN or Inf. ... Signals are cleared on startup, COLD, BYE, ABORT, ABORT" -mhx] ... A forth compiler/text interpreter isn't an engineering application. ... The role of the forth interpreter is to compile and debug apps. ...
    (comp.lang.forth)
  • Re: Purpose of the LAMBDA keyword?
    ... Actually it is possible to compile dynamic scoping as well, ... compiled lexical scope is more efficient. ... I can't recommend "The Art of the Interpreter" more highly. ...
    (comp.lang.scheme)