AI Origins · Lesson 10

Blocks World Parser

How does move A onto B become an instruction? Take a sentence apart, match a rule, then test it with four blocks.

1 Split into words 2 Match a rule 3 Check and act

Words have jobs. Order gives them structure.

Tokenizing splits text into pieces called tokens. In this lab, each word is a token. Parsing checks their order against a grammar and builds a structured instruction. Understanding that structure does not mean the move is possible.

movesource blockontodestination block

Compare move A onto B with move B onto A. Same words, different jobs for A and B.

Command workbench

Inspect a sentence before you run it

Edit a command or choose an example. The parser updates as you type; the blocks change only when you press Run. Initially A sits on B, and D sits on C.

Write a command

Commands you can use
  • move X onto Y
  • move X to table
  • stack X on Y
  • unstack X from Y
  • clear X
  • show state

Live parse · no blocks move here

1. Tokens in order

First, lowercase the text and collapse extra spaces. Word order stays the same.

    2. Match the grammar

    + means “followed by”; | means “or”; brackets mark an optional word.

    3. Build the instruction

     

    Ready! Start with Step 1 below.

    Result of the last run

    Parse, then execute

    Waiting

    You typed—

    Parsed action—

    Blocks used—

    Execution resultRun a command

    See every tiny step

      The block table

      Inspect the world facts
       

      Your goal

      Make these two towers

      The robot will show you one move at a time.

      DB
      CA
      123

      Step 1 of 3

      First, move A out of the way

      A must move so B has an open top.

      MoveAto the table

      Press the green button.

      Three experiments: where does it fail?

      Structure

      Try move onto A B. All the words look familiar, but their order does not match a rule. Repair the sentence. This is a syntax error.

      Reference

      Try move Z to table. The sentence matches the grammar, but there is no block Z. Parsing succeeded; checking the referenced object failed.

      World rules

      Reset, then run move B to table. It parses and B exists, but A is on top. Move A first and try again. The same sentence can have a different result in a different state.

      Try it with real objects

      Label four classroom objects A–D. Write “move”, “A”, “onto”, and “B” on four slips. One partner arranges the slips; another labels the action, source, relation, and destination, then checks whether the move is possible. Swap A and B. Explain what changed before touching the objects.

      This lab uses a small, fixed grammar. Parsers also give structure to code, calculator expressions, and data files. A general language system needs much more than these command patterns.

      Quick check

      Can you separate parsing from execution?

      Choose an answer and get help right away.

      Question 1

      In “move A onto B”, which block is the destination?

      Question 2

      “move onto A B” fails at which stage?

      Question 3

      Can a command parse correctly and still fail?