Exploring Languages
with Interpreters
and Functional Programming

Chapter 43
Calculator: Modular Structure

H. Conrad Cunningham

24 November 2018

Copyright (C) 2017, 2018, H. Conrad Cunningham

Acknowledgements: I originally created these slides in Fall 2017 to accompany what is now Chapter 43, Calculator: Modular Structure, in the 2018 version of the textbook Exploring Languages with Interpreters and Functional Programming.

Browser Advisory: The HTML version of this document may require use of a browser that supports the display of MathML. A good choice as of November 2018 is a recent version of Firefox from Mozilla.

Calculator: Modular Structure

Lecture Goals

Calculator Language Modules

Values Module

Environments Module

Abstract Syntax Module

Evaluator Module

Lexical Analyzer Module

Parser Modules

REPL Modules (1)

Haskell IO program

  1. Read an input from the command line.

    If the input is an exit command, exit; else continue.

  2. Evaluate the expression after parsing.

  3. Print the resulting value.

  4. Loop back to step 1.

REPL Modules (2)

Key Ideas