\section{NAME\label{NAME}\index{NAME}}


\textbf{Fype} is \textbf{F}or \textbf{Y}our \textbf{P}rogram \textbf{E}xecution



\textbf{Fype} is \textbf{F}ree \textbf{Y}ak \textbf{P}rogramed for \textbf{E}LF



It's not a hype - it's \textbf{Fype}!

\section{SYNOPSES\label{SYNOPSES}\index{SYNOPSES}}
\begin{description}

\item[{\textbf{fype} [-[hsvTV]] file.fy}] \mbox{}
\item[{\textbf{fype} -e "fype code string;"}] \mbox{}\end{description}
\section{ABOUT\label{ABOUT}\index{ABOUT}}


Fype is not yet released! Lots of basic stuff is still missing! See the
TODO file of the source distribution of Fype!



Fype is a 32 bit scripting language created for fun. You can use it and comment on it if you like. You could also write patches and mail them to fype at dev dot buetow dot org! Or go visit the IRC channel \#coding at irc.german-elite.net and ask rantanplan.



Fype is developed under the BSD license. See the COPYING file which is included in the source tree.



Fype should be "at least as good as AWK". This does not mean it will be a replacement for AWK but it should support functions, loops and arrays like AWK does but with a different syntax. It should also get extension support like AWK has. I am not talking about GNU AWK but about New AWK, which is included in the *BSD distributions! Fype already has a few features which are not available in AWK. However, AWK has still many features which are not available in Fype as well ;)



Fancy stuff like OOP or unicode or threading is not yet planed. But fancy stuff like function pointers and closures may be considered for one of the first releases of Fype :)

\section{PARSING / CODE GENERATION\label{PARSING_CODE_GENERATION}\index{PARSING / CODE GENERATION}}


The Fype syntax is very simple and is using a maximum look ahead of 1 and a very easy top down parsing. Fype is parsing and interpreting its code simultaneous. This means, that syntax errors are only detected during program runtime.

\section{REQUIREMENTS\label{REQUIREMENTS}\index{REQUIREMENTS}}


Fype only has been tested on FreeBSD 7.0. Linux may work too. Windows support is not planned. But may work using Cygwin or SFU. Linux users have to install pmake before compiling Fype!



You will need:

\begin{verbatim}
        GNU GCC C Compiler (gcc.gnu.org)
        NetBSD Make aka pmake (GNU Make will not work)
\end{verbatim}


NetBSD Make is included in any *BSD and can be run with just \textbf{make}.

\section{GETTING STARTED\label{GETTING_STARTED}\index{GETTING STARTED}}


On Linux: Extract, compile and install Fype:

\begin{verbatim}
        tar xvjf fype.tar.bz2
        cd fype
        pmake
        sudo pmake install 
        pmake clean
\end{verbatim}


On FreeBSD: Extract, compile and install Fype:

\begin{verbatim}
        tar xvjf fype.tar.bz2
        cd fype
        make
        sudo make install 
        make clean
\end{verbatim}


Run a .fy file:

\begin{verbatim}
        fype test.fy
\end{verbatim}


See the ./examples subdir of the Fype source distribution for examples! See also fype -h for a list of all options.

\section{DATA TYPES\label{DATA_TYPES}\index{DATA TYPES}}


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

\subsection*{The basic data types\label{The_basic_data_types}\index{The basic data types}}
\begin{description}

\item[{\textit{integer}}] \mbox{}

Specifies an integer number


\item[{\textit{double}}] \mbox{}

Specifies a double number


\item[{\textit{string}}] \mbox{}

Specifies a string


\item[{\textit{number}}] \mbox{}

May be an integer or a double number


\item[{\textit{any}}] \mbox{}

May be of any type above


\item[{\textit{void}}] \mbox{}

No type


\item[{\textit{identifier}}] \mbox{}

It's a variable name or a procedure name or a function name

\end{description}
\subsection*{Explicit type conversions\label{Explicit_type_conversions}\index{Explicit type conversions}}
\begin{description}

\item[{(\textit{integer}) \textbf{integer} \textit{any}}] \mbox{}

Converts any type to an integer


\item[{(\textit{double}) \textbf{double} \textit{any}}] \mbox{}

Converts any type to a double


\item[{(\textit{string}) \textbf{string} \textit{any}}] \mbox{}

Converts any type to a string

\end{description}
\section{SYNTAX\label{SYNTAX}\index{SYNTAX}}
\subsection*{Comments\label{Comments}\index{Comments}}


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

\subsection*{Statements\label{Statements}\index{Statements}}


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:

\begin{verbatim}
        my bar = 3, foo = 1 + 2; 
        say foo;
        exit foo - bar;
\end{verbatim}
\subsection*{Paranthesis\label{Paranthesis}\index{Paranthesis}}


All paranthesis of function calls are optional. They help to make the code better readable. They also help to force precedences of expressions.

\subsection*{Scopeing\label{Scopeing}\index{Scopeing}}


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 scopeings.  The \textbf{scope} function will print out all available symbols at the current position. Here is a small example of how to use scopes:

\begin{verbatim}
        my foo = 1;
\end{verbatim}
\begin{verbatim}
        {
                # Prints out 1
                put defined foo;
                {
                        my bar = 2;
\end{verbatim}
\begin{verbatim}
                        # Prints out 1
                        put defined bar;
\end{verbatim}
\begin{verbatim}
                        # Prints out all available symbols at this
                        # point to stdout. Those are: bar and foo
                        scope;
                }
\end{verbatim}
\begin{verbatim}
                # Prints out 0
                put defined bar;
\end{verbatim}
\begin{verbatim}
                my baz = 3;
        }
\end{verbatim}
\begin{verbatim}
        # Prints out 0
        say defined bar;
\end{verbatim}
\subsection*{Control statements\label{Control_statements}\index{Control statements}}


Fype knows the following control statements:

\begin{description}

\item[{if \textit{$<$expression}$>$ \{ \textit{$<$statements}$>$ \}}] \mbox{}

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


\item[{ifnot \textit{$<$expression}$>$ \{ \textit{$<$statements}$>$ \}}] \mbox{}

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


\item[{while \textit{$<$expression}$>$ \{ \textit{$<$statements}$>$ \}}] \mbox{}

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


\item[{until \textit{$<$expression}$>$ \{ \textit{$<$statements}$>$ \}}] \mbox{}

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

\end{description}
\section{VARIABLES\label{VARIABLES}\index{VARIABLES}}


Variables can be defined with the \textbf{my} keyword. If you don't assign a value during declaration, then it's using the default integer value 0.  Variables may be changed during program runtime. Variables may be deleted using the \textbf{undef} keyword! Example of defining variables:

\begin{verbatim}
        my foo = 1 + 2;
        say foo;
\end{verbatim}
\begin{verbatim}
        my bar = 12, baz = foo;
        say 1 + bar;
        say bar;
\end{verbatim}
\begin{verbatim}
        my baz;
        say baz; # Will print out 0
\end{verbatim}


You may use the \textbf{defined} keyword to check if an identifier has been defined or
not.

\begin{verbatim}
        ifnot defined foo {
                say "No foo yet defined";
        }
\end{verbatim}
\begin{verbatim}
        my foo = 1;
\end{verbatim}
\begin{verbatim}
        if defined foo {
                put "foo is defined and has the value ";
                say foo;
        }
\end{verbatim}
\section{SYNONYMS\label{SYNONYMS}\index{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 synomyms:

\begin{verbatim}
        my foo = "foo";
        my bar = \foo;
        foo = "bar";
\end{verbatim}
\begin{verbatim}
        # The synonym variable should now also set to "bar"
        assert "bar" == bar;
\end{verbatim}


Synonyms can be used for all kind of identifiers. It's not limited to normal variables but can be also used for function and procedure names etc.

\begin{verbatim}
        # Create a new procedure baz
        proc baz { say "I am baz"; }
\end{verbatim}
\begin{verbatim}
        # Make a synonym baz, and undefine baz
        my bay = \baz;
\end{verbatim}
\begin{verbatim}
        undef baz;
\end{verbatim}
\begin{verbatim}
        # bay still has a reference of the original procedure baz
        bay; # this prints aut "I am baz"
\end{verbatim}


The \textbf{syms} keyword gives you the total number of synonyms pointing to a specific value:

\begin{verbatim}
        my foo = 1;
        say syms foo; # Prints 1
\end{verbatim}
\begin{verbatim}
        my baz = \foo; 
        say syms foo; # Prints 2
        say syms baz; # Prints 2
\end{verbatim}
\begin{verbatim}
        undef baz;
        say syms foo; # Prints 1
\end{verbatim}
\section{BUILT IN FUNCTIONS\label{BUILT_IN_FUNCTIONS}\index{BUILT IN FUNCTIONS}}


In Fype, operators are built in functions as well. The difference is, that they may be written in infix notation instead in front of the arguments. The types inside the () specify the return types.

\subsection*{Math\label{Math}\index{Math}}
\begin{description}

\item[{(\textit{any}) \textit{any} \textbf{+} \textit{any}}] \mbox{}

Special string behavior: A string will get auto convertet into an \textit{integer}.


\item[{(\textit{any}) \textit{any} \textbf{-} \textit{any}}] \mbox{}

Special string behavior: A string will get auto convertet into an \textit{integer}.


\item[{(\textit{any}) \textit{any} \textbf{*} \textit{any}}] \mbox{}

Special string behavior: A string will get auto convertet into an \textit{integer}.


\item[{(\textit{any}) \textit{any} \textbf{/} \textit{any}}] \mbox{}

Special string behavior: A string will get auto convertet into an \textit{integer}.

\end{description}
\subsection*{Conditional\label{Conditional}\index{Conditional}}
\begin{description}

\item[{(\textit{integer}) \textit{any} \textbf{==}}] \textbf{\textit{any}}
\item[{(\textit{integer}) \textit{any} \textbf{!=}}] \textbf{\textit{any}}
\item[{(\textit{integer}) \textit{any} \textbf{$<$=}}] \textbf{\textit{any}}
\item[{(\textit{integer}) \textit{any} \textbf{$>$=}}] \textbf{\textit{any}}
\item[{(\textit{integer}) \textit{any} \textbf{$<$}}] \textbf{\textit{any}}
\item[{(\textit{integer}) \textit{any} \textbf{$>$}}] \textbf{\textit{any}}
\item[{(\textit{integer}) \textbf{not} \textit{any}}] \mbox{}\end{description}
\subsection*{Definedness\label{Definedness}\index{Definedness}}
\begin{description}

\item[{(\textit{integer}) \textbf{defined} \textit{identifier}}] \mbox{}

Returns 1 if \textit{identifier} has been defined. Returns 0 else.


\item[{(\textit{integer}) \textbf{undef} \textit{identifier}}] \mbox{}

Tries to undefine/delete the \textit{identifier}. Returns 1 if success, otherwise 0 is returned.

\end{description}
\subsection*{Bitwise\label{Bitwise}\index{Bitwise}}
\begin{description}

\item[{(\textit{integer}) \textit{any} \textbf{:$<$}}] \textbf{\textit{any}}
\item[{(\textit{integer}) \textit{any} \textbf{:$>$}}] \textbf{\textit{any}}
\item[{(\textit{integer}) \textit{any} \textbf{and}}] \textbf{\textit{any}}
\item[{(\textit{integer}) \textit{any} \textbf{or}}] \textbf{\textit{any}}
\item[{(\textit{integer}) \textit{any} \textbf{xor}}] \textbf{\textit{any}}\end{description}
\subsection*{Numeric\label{Numeric}\index{Numeric}}
\begin{description}

\item[{(\textit{number}) \textbf{neg} \textit{number}}] \mbox{}

This function returns the negative value of \textit{any}


\item[{(\textit{integer}) \textbf{no} [\textit{integer}]}] \mbox{}

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


\item[{(\textit{integer}) \textbf{yes} [\textit{integer}]}] \mbox{}

This function always returns 1. The parameter is optional.

\begin{verbatim}
        # Prints out 1, because foo is not defined
        if yes { say no defined foo; }
\end{verbatim}
\end{description}
\subsection*{System\label{System}\index{System}}
\begin{description}

\item[{(\textit{void}) \textbf{end}}] \mbox{}

Exits the program with the exit status of 0


\item[{(\textit{void}) \textbf{exit} \textit{integer}}] \mbox{}

Exits the program with the specified exit status


\item[{(\textit{integer}) \textbf{fork}}] \mbox{}

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

\begin{verbatim}
        my pid = fork;
\end{verbatim}
\begin{verbatim}
        if pid {
                put "I am the parent process; child has the pid ";
                say pid;
\end{verbatim}
\begin{verbatim}
        } ifnot pid {
                say "I am the child process";
        }
\end{verbatim}

\item[{(\textit{integer}) \textbf{gc}}] \mbox{}

Executes the garbage collector and returns the number of items freed! You may
wonder why most of the time it will return a value of 0! Fype tries to free not
needed memory asap. This may change in future versions in order to gain faster
execution of scripts!

\end{description}
\subsection*{I/O\label{I_O}\index{I/O}}
\begin{description}

\item[{(\textit{any}) \textbf{put} \textit{any}}] \mbox{}

Prints out the argument


\item[{(\textit{any}) \textbf{say} \textit{any}}] \mbox{}

Same as put, but also includes an ending newline


\item[{(\textit{void}) \textbf{ln}}] \mbox{}

Just prints a newline

\end{description}
\section{SELF DEFINING PROCEDURES AND FUNCTIONS\label{SELF_DEFINING_PROCEDURES_AND_FUNCTIONS}\index{SELF DEFINING PROCEDURES AND FUNCTIONS}}
\subsection*{Procedures\label{Procedures}\index{Procedures}}


A procedure can be defined with the \textbf{proc} keyword and deleted with the \textbf{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 variabes inside of a procedure in the current namespace.

\begin{verbatim}
        proc foo {
                say 1 + a * 3 + b;
                my c = 6;
        }
\end{verbatim}
\begin{verbatim}
        my a = 2, b = 4;
\end{verbatim}
\begin{verbatim}
        foo; # Run the procedure. Print out "11\n"
        say c; # Print out "6\n";
\end{verbatim}
\subsection*{Nested procedures\label{Nested_procedures}\index{Nested procedures}}


It's possible to define procedures inside of procedures. Since procedures don't
have its 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 \textbf{defined}
keyword in order to check if a procedure has been defined or not.

\begin{verbatim}
        proc foo {
                say "I am foo";
\end{verbatim}
\begin{verbatim}
                undef bar;
                proc bar {
                        say "I am bar";
                }
        }
\end{verbatim}
\begin{verbatim}
        # Here bar would produce an error because 
        # the proc is not yet defined!
        # bar;
\end{verbatim}
\begin{verbatim}
        foo; # Here the procedure foo will define the procedure bar!
        bar; # Now the procedure bar is defined!
        foo; # Here the procedure foo will redefine bar again!
\end{verbatim}
\subsection*{Functions\label{Functions}\index{Functions}}


A function should be defined with the \textbf{func} keyword and deleted with the \textbf{undef} keyword. Function not yet return values (will be changed in future versions) and supports not yet parameter passing (will be changed in future versions). It's using local (lexical scoped) variables. If a certain variable does not exist It's using already defined variables (e.g. one scope above).

\begin{verbatim}
        func foo {
                say 1 + a * 3 + b;
                my c = 6;
        }
\end{verbatim}
\begin{verbatim}
        my a = 2, b = 4;
\end{verbatim}
\begin{verbatim}
        foo; # Run the procedure. Print out "11\n"
        say c; # Will produce an error, because c is out of scoped!
\end{verbatim}
\subsection*{Nested functions\label{Nested_functions}\index{Nested functions}}


Nested functions work the same way the nested procedures work, with the exception that nested functions will not be available any more after the function has been left!

\begin{verbatim}
        func foo {
                func bar {
                        say "Hello i am nested";
                }
\end{verbatim}
\begin{verbatim}
                bar; # Calling nested
        }
\end{verbatim}
\begin{verbatim}
        foo;
        bar; # Will produce an error, because bar is out of scope!
\end{verbatim}
\section{AUTHOR\label{AUTHOR}\index{AUTHOR}}


Paul C. Buetow (http://buetow.org)

\section{WEBSITE\label{WEBSITE}\index{WEBSITE}}


The Fype Language (https://codeberg.org/snonux/fype)

\section{SEE ALSO\label{SEE_ALSO}\index{SEE ALSO}}


awk(1) cc(1) make(1)

