Lab Check-in 7: Interpreters

Check-in questions and answers will be available after lab solutions are released.

Interpreters

Q1: REPL

Notes for Academic Interns: Ask the student the following: Explain REPL. What are the different stages and what is done in each stage?

Solution:

  1. Read

    • Calls lexer, which breaks input into tokens.
    • Calls parser, which organizes the tokens into data structures.
  2. Eval

    • Mutual recursion between eval and apply. eval evaluates expressions (through lookups or by recursively calling eval and apply).
    • apply applies an evaluated operator to its evaluated operands
  3. Print

    • Display the result of evaluating user input
  4. Loop

    • Repeat if there are more expressions to interpret.