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:
Read
- Calls lexer, which breaks input into tokens.
- Calls parser, which organizes the tokens into data structures.
Eval
- Mutual recursion between
eval
andapply
.eval
evaluates expressions (through lookups or by recursively callingeval
andapply
). apply
applies an evaluated operator to its evaluated operands
- Mutual recursion between
Print
- Display the result of evaluating user input
Loop
- Repeat if there are more expressions to interpret.