Skip to content
Owner's local time in SP:
EXPERIMENT 006 · yanawa

tiny language playground

tokens, a syntax tree, diagnostics and a bounded interpreter

activesimulatedcreated yanawa 7fd082esource ↗

Question

What does a language do with a few lines of source before it runs them? Edit a small program and see its tokens, its syntax tree, readable errors and a bounded run, one stage at a time. The syntax is a small subset read from yanawa’s design notes; yanawa has no compiler yet, and this is not it.

Bench

bench · runs in this browser
Examples

Variables, a type annotation, strings and interpolation.

Source

Spaces only, 4 per level in the examples. Blocks end where the indentation shrinks. Comments start with //.

Problems

Pick an example or edit the source. Stages update as you type.

    Stages

    The lexer cuts the source into tokens and turns indentation into indent and dedent tokens.

    What to watch

    tokens
    Before anything is understood, the text is cut into tokens: words, numbers, strings, operators. Indentation becomes indent and dedent tokens, which is how a language without braces marks its blocks.
    syntax tree
    The parser turns the flat token list into a tree that shows structure: `1 + 2 * 3` puts `*` below `+` because it binds tighter. Precedence is in the tree, not in the text.
    diagnostics
    A good message says what was expected, what was found and where. After an error the parser skips the broken line and goes on, so one mistake does not hide the next one.
    evaluation
    The interpreter walks the tree. Nothing is compiled and nothing is evaluated as JavaScript: names live in the program’s own scopes, so `process` or `constructor` are just undefined names.
    limits
    Every stage has a limit: source size, nesting depth, evaluation steps, call depth, output and string length. An infinite loop ends with a message instead of freezing the tab.

    Limits

    • This is not the yanawa compiler. yanawa is in the language-design phase and has no verified compiler yet. The syntax here is a small subset read from its design notes (revision 7fd082e), and the rules the notes leave open were decided on this page.
    • Included: let, const, fn with typed parameters, if/elif/else, while, for over a range, and/or/not, integers, strings with interpolation, booleans, // comments, print and len.
    • Not included: structs, enums, traits, nullable types, arrays, switch, floats, imports, errors as values. Type annotations (int, str, bool) are checked when the program runs; yanawa’s static type checking is not implemented.
    • A range like 1..6 excludes its end, and integer division truncates; the notes do not fix either, so they are choices made here.
    • Source is limited to 4,000 characters and 200 lines. Nothing is stored or sent anywhere.

    Fidelity

    syntaxsubset read from yanawa notes · revision 7fd082e
    yanawa compilernone exists yet · this is not it
    executionown tree-walking interpreter · bounded · no JavaScript eval
    persistencenone · source stays in this tab

    Based on the syntax and compiler-architecture notes of yanawa revision 7fd082e. The notes leave several rules open (range ends, integer division, indentation width) and this page chose its own. Nothing is compiled or evaluated as JavaScript, and the source is never stored or sent.

    Related

    yanawa syntax notesgithub ↗yanawa compiler architecture notesgithub ↗yanawa repositorygithub ↗