"You should never explain yourself more clearly than you can think."

- some famous scientist
(Nils Bohr?) (sp?)

The Vassar Interpreter (TVI) is a simple interpreter that executes a language that bears a passing resemblance to assembly language.   The purpose of the interpreter is to allow students in an introductory compiler construction course to develop a compiler that generates "executable" code while avoiding many of the complexities that are beyond the scope of an introductory course. This document gives an introduction to TVI  and covers some of the possible ways that semantic actions might be implemented. Throughout this document the phrase source program will refer to the language that will be compiled into TVI code and target program refers to the TVI source code that your compiler will generate. 

Preamble

A compiler is simply a translator, it takes a program in one language, the source language, and produces an equivalent program in another language, the target language.  There is no one single translation that a compiler can produce that is the
most correct translation.  As long as the target program "does the same thing" as the source program it is considered correct (or at least good enough).  A common pitfall is to confuse the translation of the source program with the execution of the source program.  The compiler does not need to figure out what the source program is doing, it simply needs to look at the source program statement by statement and translate it into a an equivalent series of TVI instructions.

TIP: When parsing literals don't spend a lot of time converting the strings into their integer or floating point values , (i.e. "5" into the number five).  In most instances the only thing you are going to do with literals is print them out again!

C++ Tip:  Converting numbers to strings and strings to numbers has always been a pain.  The C++ classes istrstream, ostrstream, and strstream come to our rescue!! (see sample1.cpp )

  • istrstream   : use character buffer for input
  • ostrstream  : output to a character buffer
  • strstream   : need to use ios::in or ios::out in the  constructor

Back to top

To contact us:

© Copyright 1999 Vassar College
Poughkeepsie, New York

Web pages  by
Keith Suderman Consulting