Skip to content

Program Structure

Every merx program is a Mermaid flowchart. It starts with a flowchart declaration, followed by node and edge definitions.

Flowchart Declaration

A program begins with the flowchart keyword and a direction:

mermaid
flowchart TD
    Start --> A[println 'Hello, merx!']
    A --> End

The direction specifies the layout of the flowchart diagram. It does not affect execution.

DirectionMeaning
TDTop to Down
TBTop to Bottom
LRLeft to Right
RLRight to Left
BTBottom to Top

Start and End Nodes

Every program must have exactly one Start node and one End node.

  • Start is the entry point. Execution begins here.
  • End is the exit point. When reached, the program terminates.

Both can have optional labels:

Start
Start([Start])
Start(["Start"])

End
End([End])
End(["End"])

Edges

Edges are arrows that connect nodes and define the control flow. The basic syntax is -->:

mermaid
flowchart TD
    Start --> A[println 'Hello!']
    A --> End

Execution follows the edges from Start to End, visiting each node along the way.

Process Nodes

Process nodes execute statements. They are written with square brackets []:

mermaid
flowchart TD
    Start --> A[println 'Hello, merx!']
    A --> End

In this example, node A executes println 'Hello, merx!', which prints the string to the console.

Comments

Use %% to add comments. Everything after %% until the end of the line is ignored:

mermaid
flowchart TD
    %% This is a comment
    Start --> A[println 'Hello!'] %% Inline comment
    A --> End

Putting It All Together

Here is a minimal merx program that prints a greeting:

mermaid
flowchart TD
    Start([Start]) --> A[println 'Hello, merx!']
    A --> End([End])
console
$ merx run hello.mmd
Hello, merx!