Basic

Evaluating the tree

The tree is walked and each node answers. The walk is the whole evaluator, and the evaluator is short enough to read at once.

What you will see

refuse node=div. The refusal names the node, which is the place.

About 1 min of reading

Try It

Answer a nested node

1

Answer the children

printf 'mul 2 3\n' | awk '{print $2*$3}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
6. The child answered first, which is the order.
2

Answer the parent

printf 'add 1 6\n' | awk '{print $2+$3}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
7. The parent answered after the child, which is the whole walk.
3

Refuse a bad node

printf 'div 4 0\n' | awk '{print ($3==0) ? "refuse node=div" : "answer"}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
refuse node=div. The refusal names the node, which is the place.

Data Flow

A tree to an answer
1 The children are walked first
↓
2 The node answers from the child answers
↓
3 A node that cannot answer names itself
↓
4 The answer is kept with a type
Why this works
Why the evaluator is separate from the parser

The parser answers without computing. An answer that does not compute is an answer that can be tested alone.

The walk is the contract

Every later pass walks the same tree. The walk is the shape every pass agrees on, and the agreement is the file.

Examples

A node answers after its children

The children answer first. Answering after is the order, and the order is what makes a nested answer possible.

The answer has a type

A number answers with a number. A type at this step is a claim, and the claim is checked later.

One node may refuse

A divide by zero refuses. The refusal names the node, and the node is the place in the tree.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← A tree as the meaning
Previous Lesson
A tree as the meaning
Next Lesson
Errors that name a place
Errors that name a place →