This is the second part of the YAUL series. For your convenience you can find other parts in the table of contents in Part 1 — Introduction

Last time we described features of a language we are going to write. Today we are going to define its grammar using EBNF-like notation.


We will describe the notation using the following syntax:

  • Elements can be written in any case
  • Optional elements are written in square brackets: [Optional]
  • One or more elements are written in curly brackets: {one_or_more}
  • Literals are written in quotation marks: 'literal'
  • Literals are case insensitive
  • Question marks indicates parts described in natural language


We start with defining identifiers. We will handle only latin letters, digits, and underscores. Variable’s name will need to start with letter or underscore:

We can see that IDENT is a letter_or_underscore, optionally followed by letters, digits, or underscores. We also specified all possible letters and digits we can handle.

Trivial values

Numbers are just digits, we don’t handle fractions:

Strings are just any printable characters delimited by double quotation marks:

Variables are just identifiers:

Literals are strings or numbers:

We can modify variable’s value:

We can allocate new array:

We can also allocate array using expressions:

We can get or set array’s element using:

Expression can be:

We have if:

We have loop:

We can print value:

We can define label — identifier ending with exclamation mark. We can also jump to it:

We can declare a function:

We can define its body:

We can return value from a function:

We can call functions:

Finally, our program is a list of functions or statements:


OK, we have our grammar. For now it is only for reference, since we will parse it in one of the last parts of this series. Next time we will write some code to represent values in memory and perform basic operations.