-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScalc.html
87 lines (55 loc) · 2.69 KB
/
Scalc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!-- saved from url=(0054)http://composingprograms.com/examples/scalc/scalc.html -->
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="./Scalc_files/assignments.css" rel="stylesheet" type="text/css">
<title>Scalc</title>
<style type="text/css"></style></head>
<body>
<title>Example: Scheme-Syntax Calculator</title>
<h2>Example: A Scheme-Syntax Calculator</h2>
<h3>Introduction</h3>
<p>This extended example implements a reader for Scheme lists and an
evaluator for the Calculator language, an expression language of numbers and
arithmetic call expressions.
</p><p>This example includes several files. They can be downloaded together as a
<a href="http://composingprograms.com/examples/scalc/scalc.zip">zip archive</a>.
<table cellpadding="10">
<tbody><tr>
<td><code><a href="http://composingprograms.com/examples/scalc/scheme_reader.py.html">scheme_reader.py</a></code></td>
<td>A parser for Scheme lists.</td>
</tr>
<tr>
<td><code><a href="http://composingprograms.com/examples/scalc/scheme_tokens.py.html">scheme_tokens.py</a></code></td>
<td>A tokenizer for Scheme expressions.</td>
</tr>
<tr>
<td><code><a href="http://composingprograms.com/examples/scalc/scalc.py.html">scalc.py</a></code></td>
<td>An evaluator for numbers and arithmetic call expressions.</td>
</tr>
<tr>
<td><code><a href="http://composingprograms.com/examples/scalc/buffer.py.html">buffer.py</a></code></td>
<td>Utility classes for reading multi-line input.</td>
</tr>
<tr>
<td><code><a href="http://composingprograms.com/examples/scalc/ucb.py.html">ucb.py</a></code></td>
<td>Utility functions for CS 61A.</td>
</tr>
</tbody></table>
</p><h3>The Scheme-Syntax Calculator Language</h3>
<p><b>Syntax.</b> Legal Calculator expressions are either numbers
or well-formed Scheme lists that have an operator symbol as their first
element. The latter are interpretered as call expressions. Legal operator
symbols include <code>+</code>, <code>-</code>, <code>*</code>, and
<code>/</code>.
</p><p><b>Evaluation.</b> The evaluation procedure for each operator is described
in the lecture notes section about the
<a href="http://composingprograms.com/pages/34-interpreters-for-languages-with-combination.html#a-scheme-syntax-calculator">
Scheme-Syntax Calculator</a>.
</p><p><b>Read-Eval-Print.</b> When run interactively, the interpreter reads
Scheme expressions (without quotation or dotted lists), evaluates them, and
prints the results.
</p><pre> > 2
2
> (+ 1 2 (* 3 4))
15
</pre>
</body></html>