AI Writes the Code. Why Hasn't the Syntax Changed?

Building the Test Files

Between Natural Sentences and Precise Syntax. Now it was time to make that structure work. But It Took More Than I Expected to Execute One English Sentence was different from building a language in which many sentences behave consistently.

My approach was to implement a feature first, run it through the CLI, and then write a test to record the expected behavior. With every new feature, the collection of example .flow files and tests grew. I didn't set out with a perfect testing strategy, but what mattered wasn't just having written syntax—it was knowing that syntax behaved as intended.

The language developed from assignment and output to operators, conditionals, loops, and finally functions.

Variables and Output

The first example file, examples/first-test.flow, contains:

Set user age to 20
Set pi to 3.14
Set greeting to "Hello World"
Print "Hello, World!"
Print "Age is (user age)".

This saves numbers and strings in variables, then prints values. It's short, but there is a surprising amount to check. Does the program recognize 20 and 3.14 as numbers? Treat the content inside quotes as one string? Read user age as one variable name rather than two? Replace the reference in parentheses with its actual value?

Variable names containing spaces were especially central to FlowScript. Parsing the declaration wasn't enough: the next sentence had to find the same variable again.

Set the user age to 20
Print a user age.

I made sure articles like the and a didn't change the variable's identity. Commands were also case-insensitive. The language supported boolean spellings such as yes, no, on, and off, along with no value. I didn't spend much time at that stage agonizing over the internal representation of value types, but I did need their behavior to be consistent.

Arithmetic Operations

Next came calculations. I thought supporting the four basic arithmetic operators would be straightforward, but I first had to decide where an expression began and ended.

Set price to 100
Set quantity to 2
Set subtotal to the result of (price * quantity)

Because FlowScript allows spaces inside variable names, it needs a clear boundary between a name and a calculation. I used the form the result of (...) to wrap arithmetic expressions. I had considered writing an expression directly after the result of, but it made the sentence look more complicated. Parentheses made the boundary clearer.

Then I implemented operator precedence and grouping. Of course 2 + 3 * 4 should produce a different result from (2 + 3) * 4. When you're building the language yourself, though, even that familiar rule has to be encoded in the parser.

I also added math helpers such as round, floor, and ceil, as well as display formatting with fixed(total, 2). The number 20 and the string 20.00 might look related on a screen, but they serve different purposes.

Comparison, Logical, and String Operations

Before implementing conditionals, I needed expressions that could evaluate to true or false. Instead of relying only on symbols, I used English phrases like is greater than, is equal to, and is less than or equal to.

Set user age to 20
Set adult status to user age is greater than or equal to 18
Print "Adult is (adult status)".

The parser had to recognize several consecutive words as one comparison operation. I also added and, or, and not, with explicit precedence rules.

Strings required a different way of thinking. joined with combines two strings and returns a string; contains, starts with, and ends with evaluate to booleans.

Set title to "FlowScript"
Set title status to title starts with "Flow" and not title ends with "Draft"
Print title status.

String operations felt a little less intuitive to implement than arithmetic because the concepts were different. Now a single expression system had to accommodate operations on different kinds of values and return different kinds of results.

Conditionals

Once expressions were in place, I could control which parts of a program would run.

Set user age to 15
When user age is greater than 18:
    Print "Adult".
In case user age is greater than 12:
    Print "Teen".
Otherwise:
    Print "Child".

This example should print Teen. If the first condition is false, the program tries In case, and it runs Otherwise only when no earlier condition matches.

Implementing conditionals also meant giving indentation and blocks real meaning. I needed rules for how many statements belonged to a branch and where nested blocks ended. I don't remember getting particularly stuck on this part, but it was necessary to guarantee the execution order.

Alongside When / In case / Otherwise, I added Check / Case / Default for branching based on matching values.

Loops and Lists

To run the same code repeatedly, I needed loops. But implementing For each meant I also needed a collection to iterate over. I had been thinking about list syntax already; working on loops made it a concrete feature.

Set numbers to the list of (1, 2, 3)
For each item in numbers:
    Print "Item is (item)".

The expected output is Item is 1, Item is 2, and Item is 3. Beyond counting iterations, I had to define the scope of the loop variable. item should be local to the loop block, without inadvertently overwriting an outer variable with the same name.

I went on to add Repeat, Keep doing this while, and Keep doing this until, plus Break and Continue. Tests checked that loops ran the right number of times, stopped early when instructed, and skipped to the next iteration correctly. A fractional repeat count like Repeat 2.5 times had to raise an error.

On the surface these are different English sentences. In the implementation, they differ in when they check a condition and when they stop.

Functions

Once variables and control flow worked, I wanted to reuse groups of statements rather than copy them. That meant functions. But implementing them led me back to a surprisingly basic question: what exactly is a function?

In FlowScript, I defined functions with How to.

How to calculate total using price and quantity and returns Number:
    Set calculated total to the result of (price * quantity)
    Return calculated total.

Set final amount to the result of calculate total using 100 and 2
Print final amount.

Here, calculate total is the function name, and the arguments come after using. Return specifies the value sent back to the caller. Since function names can also contain spaces, the call syntax needed clear rules to distinguish the name from its inputs.

I also had to define the scope of variables inside a function. The calculated total variable in this example should not be directly accessible outside it. Runtime tests confirm that function-local variables don't leak into the surrounding scope.

What I enjoyed most about this feature wasn't the implementation technique but the sentence itself. How to calculate total using price and quantity really does read like an explanation of how to do something. For the first time, FlowScript felt close to the language I had imagined.

Testing and Verification

As features accumulated, the tests took on different roles. Lexer tests checked whether commands, numbers, and strings became the right tokens. Parser tests checked operator precedence and whether statements produced the right AST structure. Runtime tests checked actual output, stored values, loop behavior, and function scope.

The tests include cases that are supposed to fail, too. They check whether invalid repetition counts such as Repeat 2.5 times are rejected and whether a function raises an error when it returns a value of the wrong declared type. A fixture test also checks that the example .flow files can still be tokenized without breaking.

New features sometimes affected existing ones, although I no longer remember exactly which change caused which regression. The reason for keeping tests was clear: teaching the language a new construction shouldn't make it forget an old one.

Completing the Basic Features

At first, FlowScript could execute little more than Set and Print. Now it could calculate values, compare them, branch, repeat work, and reuse instructions through functions. Individually, those are familiar programming fundamentals. Together, they were enough to express the flow of a small program.

I especially remember how enjoyable it was to read the function syntax as an English sentence. But implementing the basics wasn't the end. Handling more complex data, objects, modules, and long-running tasks would require much more.

Once I knew the basic syntax worked, the next question was how far I could take the language.