One easy way to get started at programming is to examine some typical
interactions with an interpreter for the
Imagine that you are sitting at a computer terminal. You type an
and the interpreter responds by displaying the
result of its evaluating that
displayed, which can evaluate the
statement and display the resulting value.
By the way, the program that makes the mouse click
the mouse click. Such scripts were a central objective in
(More precisely, the expression that you type consists of the numerals that
represent the number in base 10.)
If you ask our script to evaluate the expression statement
by clicking it, it will respond by creating a separate
browser tab where the statement is shown, with the option
to evaluate the statement by pressing a
One kind of statement is an
expression statement, which consists of an
expression, followed by a semicolon.
A simple kind of an expression is a number.
Click on the primitive expression statement, and see what happens!
Expressions representing numbers may be combined with operators
*) to form a
compound expression that represents the
application of a corresponding primitive
function to those numbers. For example,
any of the following expression statements
by clicking on it:
Expressions such as these, which contain other expressions
as components, are called combinations.
Combinations that are formed by an
operator symbol in the middle, and
operand expressions to the left and right of it,
The value of an operator combination is
obtained by applying the function specified by the operator to the
arguments that are the values of the operands.
The convention of placing the operator between the operands is
the mathematical notation that the reader is most
likely familiar with from school and everyday life.
As in mathematics, operator combinations can
be nested, that is, they
can take arguments that themselves are operator combinations:
As usual, parentheses are used to group operator combinations
conventions when parentheses are omitted;
multiplication and division
bind stronger than
addition and subtraction.
We say that *
have higher precedence
additions and subtractions are read from left to right, as are
sequences of multiplications and divisions. Thus,
We say that the operators
There is no limit (in principle) to the depth of such nesting and to
It is we humans who might get confused by still relatively
simple expressions such as
3 * 2 * (4 + (3 - 5)) + 10 * (27 / 6);
which the interpreter would readily evaluate to be 57. We can help
ourselves by writing such an expression in the form
3 * 2 * (4 + (3 - 5))
10 * (27 / 6);
to visually separate the major components of the expression.
Even with complex expressions, the interpreter always operates in the
same basic cycle: It reads
from the terminal,
and prints the result.
This mode of operation is often expressed by saying that the
interpreter runs in a
Observe in particular that it is not necessary to explicitly
instruct the interpreter to print the value of the