The Fype Programming Language

Published at 2010-05-09T12:48:29+01:00; Updated at 2021-05-05

Fype is an interpreted programming language created by me for learning and fun. The interpreter is written in C. It has been tested on FreeBSD and NetBSD and may also work on other Unix like operating systems such as Linux based ones. Besides learning and fun, there is no other use case of why Fype exists as many other programming languages are much faster and more powerful.

The Fype syntax is straightforward and uses a maximum look ahead of 1 and an effortless top-down parsing mechanism. Fype is parsing and interpreting its code simultaneously. This means that syntax errors are only detected during program runtime.

Fype is a recursive acronym and means "Fype is For Your Program Execution" or "Fype is Free Yak Programmed for ELF". You could also say, "It's not a hype - it's Fype!".

Table of Contents

Object-oriented C style

The Fype interpreter is written in an object-oriented style of C. Each "main component" has its own .h and .c file. There is a struct type for each (most components at least) component, which can be initialized using a "COMPONENT_new" function and destroyed using a "COMPONENT_delete" function. Method calls follow the same schema, e.g. "COMPONENT_METHODNAME". There is no such as class inheritance and polymorphism involved.

To give you an idea of how it works here as an example is a snippet from the main Fype "class header":

And here is a snippet from the primary Fype "class implementation":

Data types

Fype uses auto type conversion. However, if you want to know what's going on, you may take a look at the following basic data types:

There is no boolean type, but we can use the integer values 0 for false and 1 for true. There is support for explicit type casting too.

Syntax

Comments

Text from a # character until the end of the current line is considered being a comment. Multi-line comments may start with an #* and with a *# anywhere. Exceptions are if those signs are inside of strings.

Variables

Variables are defined with the "my" keyword (inspired by Perl :-). If you don't assign a value during declaration, it uses the default integer value 0. Variables may be changed during program runtime. Variables may be deleted using the "undef" keyword! Example:

You may use the "defined" keyword to check if an identifier has been defined or not:

Synonyms

Each variable can have as many synonyms as wished. A synonym is another name to access the content of a specific variable. Here is an example of how to use it:

Synonyms can be used for all kind of identifiers. It's not limited to standard variables but can also be used for function and procedure names (more about functions and procedures later).

The "syms" keyword gives you the total number of synonyms pointing to a specific value:

Statements and expressions

A Fype program is a list of statements. Each keyword, expression or function call is part of a statement. Each statement is ended with a semicolon. Example:

Parenthesis

All parenthesis for function arguments is optional. They help to make the code better readable. They also help to force the precedence of expressions.

Basic expressions

Any "any" value holding a string will be automatically converted to an integer value.

Bitwise expressions

Numeric expressions

... returns the negative value of "number":

... returns 1 if the argument is 0; otherwise, it will return 0! If no argument is given, then 0 is returned!

... always returns 1. The parameter is optional. Example:

Control statements

Control statements available in Fype:

... runs the statements if the expression evaluates to a true value.

... runs the statements if the expression evaluates to a false value.

... runs the statements as long as the expression evaluates to a true value.

... runs the statements as long as the expression evaluates to a false value.

Scopes

A new scope starts with an { and ends with an }. An exception is a procedure, which does not use its own scope (see later in this manual). Control statements and functions support scopes. The "scope" function prints out all available symbols at the current scope. Here is a small example:

Another example including an actual output:

Definedness

... returns 1 if "identifier" has been defined. Returns 0 otherwise.

... tries to undefine/delete the "identifier". Returns 1 if it succeeded, otherwise 0 is returned.

System

These are some system and interpreter specific built-in functions supported:

... exits the program with the exit status of 0.

... exits the program with the specified exit status.

... forks a subprocess. It returns 0 for the child process and the PID of the child process otherwise! Example:

To execute the garbage collector do:

It returns the number of items freed! You may wonder why most of the time, it will produce a value of 0! Fype tries to free not needed memory ASAP. This may change in future versions to gain faster execution speed!

I/O

... prints out the argument

is the same as put, but also includes an ending newline.

... just prints a new line.

Procedures and functions

Procedures

A procedure can be defined with the "proc" keyword and deleted with the "undef" keyword. A procedure does not return any value and does not support parameter passing. It's using already defined variables (e.g. global variables). A procedure does not have its own namespace. It's using the calling namespace. It is possible to define new variables inside of a procedure in the current namespace.

Nested procedures

It's possible to define procedures inside of procedures. Since procedures don't have their own scope, nested procedures will be available to the current scope as soon as the main procedure has run the first time. You may use the "defined" keyword to check if a procedure has been defined or not.

Functions

A function can be defined with the "func" keyword and deleted with the "undef" keyword. Function do not yet return values and do not yet supports parameter passing. It's using local (lexical scoped) variables. If a certain variable does not exist, when It's using already defined variables (e.g. one scope above).

Nested functions

Nested functions work the same way the nested procedures work, except that nested functions will not be available anymore after the function has been left!

Arrays

Some progress on arrays has been made too. The following example creates a multidimensional array "foo". Its first element is the return value of the func which is "bar". The fourth value is a string" 3" converted to a double number. The last element is an anonymous array which itself contains another anonymous array as its final element:

It produces the following output:

Fancy stuff

Fancy stuff like OOP or Unicode or threading is not planed. But fancy stuff like function pointers and closures may be considered.:)

May the source be with you

You can find all of this on the GitHub page. There is also an "examples" folders containing some Fype scripts!

https://codeberg.org/snonux/fype

E-Mail your comments to `paul@nospam.buetow.org` :-)

Back to the main site