Target language specifications

This is the full description of the YANI language. It introduces the structure of programs, as well as every features such as keywords or operators.

Program structure

I’m going to briefly present the YANI language so that you quickly get an idea of YANI possibilities. YANI language is in LL(1) format so that a one symbol lookahead single track recursive descent parser can be constructed.

A YANI program consists of zero or more functions declarations followed by a statement which may call one or more of the previously declared functions. By example:


function f1(x)=x*x;
function f2(x)=x*x*x;
f1(10)*f2(12).

A YANI program must end with a point.

Mathematical expression

The YANI language can deal with basic mathematical expressions. To achieve that, there are:
- operators: + (plus), - (minus), * (times), /(divides) and % (modulo);
- priorities : mathematical priorities and optionally parenthesis.

FL(0) works exclusivally with integers. Example:


(3+4*6)%4-a/5

Comparaisons

Two expressions can be compared by using the following symbols:
- = equal;
- > greater than;
- < lower than;
- >= greater than or equals;
- <= lower than or equals.

This is usually used inside conditional statements. For instance:


a+3>=b+5

In YANI, true equals zero and false a value different of zero.

Conditional statements

YANI provides for conditional statements of the form


if <expression> then
    <statement>
else
    <statement>

Please note that any if statement must be associated by an else.

Condition statements can be nested to any depth.

Functions

The YANI language allows definition of functions of the following form:


function fn(n1,n2)=
    <statement>
;

Functions must have a unique name using the same rules of identifiers. They can have one or more named parameters. Functions are declared at the same level so they can’t be nested. However recursive functions are allowed. Example:


function fib(n)=
    if n<=2 then
         1
    else
         fib(n-1)+fib(n-2)
    ;

Identifiers

Identifiers are only used in functions. They must be declared within a function and their scope is the function body. Their names must be unique in their scope, and begins by a letter followed by zero or more digits/letters. Name lengths are limited to 32 characters.

Input-Output

There is no input or output instruction. All functions will return an integer result. It is the runtime system which has to display the final result.

Stay tuned!
What others think

«First of all, I'd like to commend you for a neatly maintained site and well thought out, useful, and free plugins (...) Many thanks and keep it up!»

Guavawho