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.
Values module Values
(Ch. 42)
Secret: specific representation for values supported by language
Environments module Environments
(Ch. 42)
Secret: specific representation for environments used by interpreter
Abstract_Synax module AbSynCalc
(Ch. 42)
Centralize definitions of abstract syntax
Evaluator module EvalCalc
(Ch. 42)
Secret: implementation of language semantics
Lexical_analyzer module LexCalc
common to both parsers (Ch. 44)
Secret: lexical structure of concrete language (identifiers, literal constants, operators, etc.)
Parser abstract module (Ch. 44)
Secret: how concrete syntax recognized and translated to abstract syntax
Prefix syntax Parser module ParsePrefixCalc
Infix syntax Parser module ParseInfixCalc
Haskell IO
program
Read an input from the command line.
If the input is an exit command, exit; else continue.
Evaluate the expression after parsing.
Print the resulting value.
Loop back to step 1.
Uses Parser and Evaluator modules
Separate versions
infix: InfixCalcREPL
prefix: PrefixCalcREPL
Expressons plus REPL commands :set
, :display
, :quit
Modular structure for Calculator language interpreter
7 modules
cohesive units
secrets
abstract interfaces