Lecture: Mini Language Interpreter Part III: adding procedures

Background Material

Reading

Theme

In this lecture we extend the mini language from lecture on mini language to include user defined functions and function calls. The implementation of the mini language from lecture mini2 is extended to include functions.

In this implementation we will insist that all functions are closed. I.E. they only communicate with the calling environment through parameter passing and their meaning is determined soley from the statements in their definition and the parameter values. In the next lecture, we will deal with non-local reference and scope rules.

Topics

  1. Review implementation of the mini language from Lecture mini2.
  2. Procedures and activation records.
  3. Parameter passing: pass by value, pass by reference, pass by value-result (also called copy-in, copy-out or copy-restore), pass by name.
  4. Extended syntax (define statement and function call). See programext.y for the extended grammar and parser, and programext.l for the extended tokens and scanner.
  5. Implementation of procedures (Proc class). Interface and implementation in programext.h and programext.cpp. See tproc.cpp for main programs that tests the Proc class.
  6. Implementation of define statements and programs with procedures. See tprogext.cpp for main programs that tests procedures.
  7. Recursive procedures (already supported) See tprogrec.cpp for main programs that tests procedures.
  8. Interfacing with bison (interpreterext.ypp, programext.y, programext.l)
    1. Sample programs with procedures
      1. add.p
      2. addr.p - recursion
    2. Instructions for building interpreter
      1. bison interpreterext.ypp # to create C++ file interpreter.tab.cpp
      2. bison -d progamext.y # to create header file program.tab.h for lexer
      3. flex programext.l
      4. gcc -c lex.yy.c # create the object file lex.yy.o
      5. g++ interpreterext.tab.cpp programext.cpp lex.yy.o -o interpreterext # compile and link

    References and programs

    Exercises

    Created: April 10, 2008 (revised April 11, 2013) by jjohnson AT cs DOT drexel DOT edu