Lecture: Mini Language Interpreter Part II: adding statements

Background Material



This lecture completes the implementation of the mini language from lecture on mini language interpreter started in mini1. The languages statements, assignment, if, and while, are implemented. This is done by adding classes for each of these statements, inherited from a base class for statements. In addition a class for statement lists is provided. This allows a complete program to be stored (environment plus statement list) and interpreted.


  1. Review implementation of expressions and symbol table from Lecture on expression trees.
  2. Classes for statements (Stmt, AssignStmt, IfStmt, and WhileStmt) and statement lists (StmtList). Interface and implementation in program.h and program.cpp. See tstmt.cpp and tstmtlist.cpp for main programs that test these classes.
  3. Implementation of mini language programs Interface and implementation in program.h and program.cpp. See tprog.cpp for main programs that tests the Program class.
  4. Interfacing with bison (interpreter.ypp, program.y, program.l)
    1. bison interpreter.ypp # to create C++ file interpreter.tab.cpp
    2. bison -d progam.y # to create header file program.tab.h for lexer
    3. flex program.l
    4. gcc -c lex.yy.c # create the object file lex.yy.o
    5. g++ interpreter.tab.cpp program.cpp lex.yy.o -o interpreter # create the object file lex.yy.o

References and programs


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