This document focuses on the grammar of the Z Graph Language (ZGL).


  • A ZGL file must contain only UTF-8 encoded Unicode characters.
  • ZGL is case sensitive.
  • Whitespace means tab, space, linefeed, or carriage return [ \r\t\n].
  • A file contains zero or more items.
  • Each item must be terminated by a semicolon (;).


ZGL has two kinds of comments:

// Here is a line comment.

/* Here is a block comment.
   It can span multiple lines. */


An item may be a statement or expression.


Here are examples of the three kinds of statements.

A use statement:

:use pop_culture;

A bind statement:

url = ;

An alias statement:

:alias /Moriarty /person/fiction/James_Moriarty;


An expression is either a z graph expression (ZGE) or non-graph expression (NGE).

Simple ZGE

Let's start with a simple ZGE, defined as one that does not have curly braces ({ }).

This statement has one z graph expression (ZGE):

/person/Ben_Franklin founded /university/Penn;

This is the simplest kind of ZGE, consisting of three whitespace separated NGE's.  When evaluated, it creates an edge (founded) from the source node (/person/Ben_Franklin) to the target node (/university/Penn).

Here is a more complex example:

"Poor Richard" pseudonym_of /person/Ben_Franklin aka "The First American";

This statement contains five whitespace separated NGE's and creates two edges.  It is equivalent to the following two statements:

"Poor Richard" pseudonym_of /person/Ben_Franklin;
/person/Ben_Franklin aka "The First American";

The syntax up to this point is sufficient to define all z graphs.

Grouped ZGE

You can reduce repetition in some cases by using curly braces ({}). The braces create a group.

For example, the following item is a ZGE, which contains a group:

A {
  E1 N1,
  E2 N2,
  E3 N3 E4 N4,

The above ZGE is equivalent to the following ZGEs:

A E1 N1;
A E2 N2;
A E3 N3 E4 N4;

Here is a more realistic example:

/person/Ben_Franklin {
  printed /newspaper/The_Pennsylvania_Gazette,
  born_in /place/USA/Massachusetts/Boston,
  note "
    At age **17**, Franklin ran away to Philadelphia.
  " format markdown,

In this case, the first NGE, /person/Ben_Franklin, is reused multiple times in the group that follows.  So, the statement above is equivalent to these three statements:

/person/Ben_Franklin printed /newspaper/The_Pennsylvania_Gazette;
/person/Ben_Franklin born_in /place/USA/Massachusetts/Boston;
/person/Ben_Franklin note "At age **17**, Franklin ran away to Philadelphia."
  format markdown;

You can see that the /person/Ben_Franklin is used three times as the source node for three different edges. 


This is only a brief overview.  Please read the Strings page for details and examples.

Strings use UTF-8 encoding.  Any unicode character is allowed (directly or escaped).  For example, "Erdős" and "Erd\u{151}s" are valid strings.

ZGL offers many options to customize how string literals work:

option (enabled by default) flag to disable
escaping -e
continuations -c
unindent leading whitespace -l
discard trailing whitespace -t
discard empty first line -a
discard empty last line -z

Each option above is enabled by default. Each can be disabled individually by using it as a prefix; e.g. -l"..." or -lta"...".

Example 2: With escaping disabled (-e prefix) plus using continuations (\) ...

-e"In APL \ is called Expand when used to insert \
fill elements into arrays, and Scan when used to \
produce prefix reduction (cumulative fold)."

... The trailing backslashes are treated as line continuations.  This gives a string with one \ and no newlines.

Examples 3a, 3b: Showing off unindent leading whitespace, discard empty first line, and discard empty last line ...

quote = "
        Gathering places
        influence norms,
          through action
           and inaction.
quote = "Gathering places
influence norms,
  through action
   and inaction.";

Visit the Strings page to learn more.

Last update: