First Steps

Three Minutes in Code Village

You don't need to know any code.

Come along with Liney and visit three gates in Code Village. A different line of code will visit each gate.

Open each gate once. The pictures tell the story, and the record cards show what the Topaz compiler actually recorded.

Liney

I'm Liney. I'll show you around today!

Snip's Gate

Our first visitor 1 + 2

Snip

Before you come in, let me make a few cuts.

Let Snip cut
Pieces from the Topaz 5.21.1 compiler
  1. 1
  2. +
  3. 2

The spaces aren't kept as separate pieces here. Three pieces remain.

Pieces like these are called tokens.

Twig's Gate

Here comes a different visitor. 1 + * 2

Liney

There's one more symbol this time.

Twig

Snip handed me four pieces.

Let's see how they fit together.

Hang it on the tree

This is where it stops.

In plain wordsThe plus sign needs a value after it, but a multiplication sign came first.

Topaz compiler 5.21.1 record

TPZ2001

expected an expression

Where it points The fifth character, *

Putting tokens together by grammar rules to find the structure of code is called parsing.

This visitor stops here. Let's go meet another one.

Tami's Gate

Our third visitor 1 + "apple"

This visitor has already passed two checks.

Marks on the visitor's card

  • Pieces identified
  • Tree formed

Liney

The tree looks fine. What else is there to check?

Tami

Now I'll check what kind of value each one is.

Show it to Tami

This time, the tree was formed, but the next check found a problem.

In plain wordsThe left value is an integer, int, and the right value is a string, string. Topaz's + can't take this integer and string together as they are.

Topaz compiler 5.21.1 record

TPZ5001

`+` needs matching int, float, string, BigInt, or Decimal operands, found `int` and `string`

Where it points Characters 1 through 11, the whole expression

The kind of a value is called its type. Checking whether an operation can use those types is called type checking.

Look how far we've come

Some visitors stopped along the way, but other code can pass all three gates.

1 + 2

This code was split into pieces, formed a tree, and passed its type check.

Journey record

  • Pieces identified
  • Tree formed
  • Type check passed

These gates show three things the Topaz compiler does while reading and checking code. There's more happening along the way and beyond.

Momo and Tinker are waiting farther down the road.

Where would you like to go next?