[an error occurred while processing this directive]

Class 2 Notes

Lecture Slides, Suitable For Printing

Notes and Questions

What is a formal system?





What is the difference between a formal system and a language?





Languages are made of:

When learning a foreign language, which of primitives, means of combination or means of abstraction is hardest to learn?



Who was Admiral Grace Hopper and what did she do?




Compiler: A program that translates between two languages, usually from a high-level programming language to machine code.

What is the difference between a compiler and an interpreter?




Why did John Backus want a precise way of describing languages?



Backus Naur Form (BNF): A way of describing the surface forms in a language using replacement rules in the form:

non-terminal ::= replacement
The rule means whenever you have what is on the left side of the ::=, you can replace it with what is on the right side.

What strings can the following BNF grammar produce?

Sentence ::= Food Comparator Food
Food ::= Bodo's Bagels
Food ::= Krispy Kreme Donuts
Comparator ::= are better than
Comparator ::= are worse than



What strings can the following BNF grammar produce?

Sentence ::= I like FoodList
FoodList ::= Food
FoodList ::= Food and FoodList
Food ::= Bodo's Bagels
Food ::= Krispy Kreme Donuts



Backus-Naur Form Scheme Grammar with Rules of Evaluation

Expression ::= PrimitiveExpression
PrimitiveExpression ::= Number | #t | #f | Primitive Procedure

Evaluation Rule 1: Primitives. If the expression is a primitive, it evaluates to __________________________________________.

Expression ::= NameExpression
NameExpression ::= Name
Evaluation Rule 2: Names. If the expression is a name, it evaluates to __________________________________________.
Expression ::= ApplicationExpression
ApplicationExpression ::= (Expression MoreExpressions)
MoreExpressions ::=
MoreExpressions ::= Expression MoreExpressions
Evaluation Rule 3: Application. If the expression is an application:
    (a) Evaluate all the subexpressions (in any order)
    (b) Apply the value of the first subexpression to the values of all the other subexpressions.

Application Rule 1: Primitives. If the procedure to apply is a primitive, __________________.

Application Rule 2: Constructed Procedures. If the procedure is a constructed procedure, ___________________ the body of the procedure with each formal parameter replaced by the corresponding actual argument expression value.

Expression ::= ProcedureExpression
ProcedureExpression ::= (lambda (Parameters) Expression)
Parameters ::=
Parameters ::= Name Parameters
Evaluation Rule 4: Lambda. Lambda expressions evaluate to a procedure that takes the given parameters and has the expression as its body. (Do not do anything until it is applied.)
Expression ::= IfExpression
IfExpression ::= (if ExpressionPredicate ExpressionConsequent ExpressionAlternate)
Evaluation Rule 5: If. To evaluate an if expression, (a) evaluate the ___________________; then, (b) if the value of the predicate expression is ___________ then the value of the if expression is the value of the alternate expression; otherwise, the value of the if expression is the value of the _____________________________________.
Tough Questions
Show how the Rules of Evaluation would evaluate (square 4) where square is defined by:
(define square (lambda (x) (* x x)))
You will need more space for this, but it is worth doing. (For an exam, say. Hint, wink, nudge.) Of course, you know the final value, but the important thing is to understand how following the Scheme evaluation rules steps will produce that value. You should be confident that you can determine the value of any Scheme expression just by following the evaluation rules systematically.

Evaluation Rule 3a does not say in what order the subexpressions should be evaluated in. For example, we could evaluate them left to right, or right to left, or in any other order. This is like the MIU-system Rule 3 that does not say which occurance of III should be replaced. Does it ever matter in which order the subexpressions of an application are evaluated? (Tough question, but try to think of a Scheme expression where it would make a difference.)

Links

I flunked out every year. I never studied. I hated studying. I was just goofing around. It had the delightful consequence that every year I went to summer school in New Hampshire where I spent the summer sailing and having a nice time.
John Backus (Since you probably don't get to spend the summer in New Hampshire if you flunk out, you may not want to follow his advice here.)
Frankly, we didn't have the vaguest idea how the things would work out in detail... We struck out simply to optimze the object program, the running time, because most people at that time believed you really couldn't do that kind of thing.
John Backus (on FORTRAN language and compiler, quoted in 1966)
"When I use a word," Humpty Dumpty said, in a rather scornful tone, "it means just what I choose it to mean - nothing more nor less."
"The question is," said Alice, "whether you can make words mean so many different things."
"The question is," said Humpty Dumpty, "which is to be master that's all."

Through the Looking Glass — Chapter VI: Humpty Dumpty, Lewis Carroll
"Somehow it seems to fill my head with ideas - only I don't exactly know what they are!"
Alice, in Alice and Wonderland by Lewis Carroll after hearing The Jaberwocky.
The best book on programming for the layman is Alice in Wonderland;
but that's because it's the best book on anything for the layman.

Alan Perlis, author of SICP Forward and First Turing Award (biggest prize for Computer Science) Winner
[an error occurred while processing this directive]