THE LANGUAGE

       GENERAL
       SEPARATORS
       OPERATORS
       CONDITIONAL EXPRESSIONS
       LOOPS
       FUNCTIONS
       DIRECTIVES
       VARIABLES
       MATHEMATICAL FUNCTIONS
       INPUTS OUTPUTS

















































GENERAL

        Language syntax ANYFLO takes the familiar, the C language,with simplifications and extensions:

simplifications
extensions
comments

Simplifications

1) No statements: Types and dimensions of objects are defined dynamically, so we can write successively:
       x = 1; x is a number.
       x = 1,2,3; x is a array of numbers.
       x = "toto"; x is a string.
       x = "toto",[1,6]; x is of hybride type.
To determine the type of a variable v do status var("v").

2) The parentheses can be omitted when there is no ambiguity.
Examples:
       $(1+2*3); or $ 1+2*3; produces the same result 7
       $(cos(PI/4)); or $ cos PI/4; produces the same result 0.707107

3) No structure. In fact any variable is an array hybrid example: x=1,"AB",[2,5];, defines x as a structure whose first field is the number 1, the second field is the string "AB" and whose third field is the array (2,3,4,5).

Extensions

1) Calculations on arrays, as follow:
       x = [1,5];y = [11,15];
       $(x + 2 * y); prints (23.0,26.0,29.0,32.0,35.0)

2) Function returns any object, so:
       f(n)
       {
       return[1,n];
       }

       $f(5); prints (1.0,2.0,3.0,4.0,5.0)

3) The switch is generalized to arbitrary expressions.

Comments

All text between / * and * / is considered a comment and ignored by the compiler.
The same goes for the text between / / and the end of line.

SEPARATORS

Words are separated by:
       Spaces
       Tabs
       Newline
       operators
       Parentheses ()
       Brackets []
       Acollades {}

OPERATORS

Arithmetic operators
logical
logical connectors

Arithmetic operators

1) + Is the addition operator.
Examples:
       1 + 3; returns 4
       (1,2,3) + (4,5,6); returns 5.0 7.0 9.0
Remarque: x = x + 1; can be written as x++; (after the increment is made use of x) ou ++x; (the increment is made of x before use)
Examples:
       x=1;$x++;$x; prints 1.0 2.0
       x=1;$++x;$x; prints 2.0 2.0

2) - is the subtraction operator.
Examples:
       1 - 3; returns -2
       (1,2,3) - (4,5,6); returns -3.0 -3.0 -3.0
Notes:
       x = x - 1; can be written as x--; (after the decrement is made use of x) ou --x; (the decrement is made of x before use)
Examples:
       x=1;$x--;$x; prints 1.0 0.0
       x=1;$--x;$x; prints 0.0 0.0
       As a unary operator - sign changes the sign of an expression.
Examples:
       $(-1); prints -1
       $(-(1 - 3)); prints 2

3) * is the multiplicaction operator.
Examples:
       2 * 3; returns 6
       (1,2,3) * (4,5,6); returns 4.0 10.0 18.0

4) / is the division operator.
Examples:
       1 / 2; returns 0.5
       (1,2,3) / 2; returns 0.5 1.0 1.5

       Division by zero causes a WARNING message (but does not crash the program).

5) ^ is the operator of exponentiation.
Examples:
       2 ^ .5; returns the square root of 2: 1.414214
       2 ^ -1; returns the inverse of 2: 0.5


Assignment
6) = is the operator of assignment.
Examples:
       x = 1; sets the variable x the value 1.
Notes:
1) Multiple assignment:
       z=y=x=2; is equivalent to x=2;y=2;z=2;
2) x = op expr is equivalent to x = x op expr
Examples:
       x += 2; is equivalent to x = x + 2;
       x -= 1; is equivalent to x = x - 1;
       x *= 5; is equivalent to x = x * 5;
       x /= 2; is equivalent to x = x / 2;
       x ,=(1,2,3,4); is equivalent to x = x,(1,2,3,4);

Logical operators

1) == is the operator of equality.
Examples:
       7 == 7; produces 1 (true)
       1 == 0; produces 0 (false)

2) < is the operator of lower.
Examples:
       1 < 2; returns 1 (true)
       1 > 2; returns 0 (false)

3) <= is the operator of less than or equal.
Examples:
       7 <= 7; returns 1 (true)
       7 <= 6; returns 0 (false)

4) > is the operator of superior
Examples:
       1 > 0; returns 1 (true)
       1 > 2; returns 0 (false)

5) >= is the operator of greater than or equal.
Examples:
       5 >= 5; returns 1 (true)
       5 >= 4; returns 0 (false)

6) != is the operator of different.
Examples:
       1 != 2; returns 1 (true)
       1 != 1; returns 0 (false)

7) ~ is the operator of little different.
Examples:
       1 ~ 1.05; returns 1 (true)
       1 ~ 1.5; returns 0 (false)
Note:
       The default precision is 0.1 and can be modified by the command: precision(valeur).
Examples:
       precision(10)(1 ~ 10; produces 1 (true)
       precision(1);1 ~ 2.1; produces 0 (false)

8) || is the operator of or logic.
Examples:
       0 || 0; produces 0 (false)
       0 || 1; produces 1 (true)
       1 || 0; produces 1 (true)
       1 || 1; produces 1 (true)

9) && is the operator of and logic.
Examples:
       0 && 0; produces 0 (false)
       0 && 1; produces 0 (false)
       1 && 0; produces 0 (false)
       1 && 1; produces 1 (true)

10) ! is the operator of the logical negation'.
Examples:
       !0; returns 1 (true)
       !1; returns 0 (false)
       !(1<0); returns 1 (true)
Notes:
! returns NIL.
!"string" returns NIL.

logical connectors

1) & is the connector and.
Examples:
       1 & (1 < 2); produces 1 (true)
       1 & (1 > 2); produces 0 (false)

2) | is the connector or.
Examples:
       $(1 | (1 > 2)); prints 1 (true)
       $(0 | (1 > 2)); prints 0 (false)

CONDITIONAL EXPRESSIONS

if
switch

The if statement

1) 1st form:
       if (condition) { ... }
Examples:
       if (1 > 0) $"OK"; prints OK
       if (1 < 0) $"OK"; prints nothing

2) 2nd form:
       if (condition) { ...} else { ... }
Examples:
       if (1 > 0) $"OK" else "BAD"; prints OK
       if (1 < 0) $"OK" else "BAD"; prints BAD

The switch statement

Syntax:
switch(expr)
       {
       case(expr1):
       ...
       break
       case(expr2):
       ...
       break
      
       ...
      
       default:
       ...
       }

Note:
       While in C a case is necessarily limited to integers, in anyflo they can be any evaluable parenthesized expression.
Examples:
       case 1:
       case(-1.2):
       case((1,2,3)):
       case("AB"):
       case(x+2*y):
       etc...

LOOPS

for
while
goto

Loops for

1st form: for(initialisation;condition;increment) {...}
Examples:
       for(i=1;i<=5;i++) $i; prints 1.0 2.0 3.0 4.0 5.0
       i=1;for(;i<=5;i+=1)$i; prints le meme resultat
       for(i=1;i<=5;)$i++; prints le meme resultat
       i=1;for(;;){$i;if(i++>4)break}; prints le meme resultat

2nd form: for(i=debut,end,step) {...}
Examples:
       for(i=1,5)$i; prints 1.0 2.0 3.0 4.0 5.0
       for(i=1,5,2)$i; prints 1.0 3.0 5.0
Note:
       The second form is executed faster, but the boundaries can not be changed in the body of the loop.

The while loop

Syntaxe: while(condition) {...}
Examples:
       i=1;while(i++<5)$i; prints 2.0 3.0 4.0 5.0
       i=1;while(1){$i;if(i++>4)break}; prints the same result
Exercises:
       a=1;b=10;for(i=1;i<=b;i++){$i;b--}
       a=1;b=10;for(i=a,b){$i;b--}
       3) for(i=1,6){for(j=1,6)$"*";$"\n"}

The branch instruction goto


Example:
       i=1;A:$i++;if(i<5)goto A;
       prints 1.0 2.0 3.0 4.0

FUNCTIONS

Writing
Definition
Call
formal parameters
Note
Parameter of type function
Dynamic function
Local function

Writing

       In interactive mode (after the question mark of the interpreter) any expression followed by carriage return is evaluated.
       A function is a sequence of lines of code executed on demand by the mention of his name.
       Function can be written as either:
       1) With the text editor ANYFLO. edit func("").
       2) With any text editor (not encoding the text) outside ANYFLO (eg with vi UNIX editor or Visual C++ on Windows), the file name extension is .func (example:foo.func).
Note:
       Extension .fon also applies (but not recommended since it can be confused with the font files on Windows).
       Any number of functions can be written in the same file.

Definition

A function is defined by:
       1) A name followed by a list of formal parameters in parentheses.
This name must not beging with the character _ (reserved for functions written in C).
       2) A brace
       3) A series of instruction lines
       4) A closing brace
Example:
       f(x, y)
       {
       $(x,y);
       }
The function name must not be that of a command.

Call

       A function is called by its name followed by a list of actual parameters in parentheses.
Examples:
       define function f by:
       f(x,y){$x,y;NL;}
       f(1, 2); produces 1.0 2.0
       f("AB",([1,5])); produces AB 1.0 2.0 3.0 4.0 5.0

formal parameters

A formal parameter corresponding to no call parameter is set to NIL.

Functions can be passed as parameters to a function.
Example:
       a(b, n)
       func b;
{
       $b(n);
}

       a("cos", PI/4); produces 0.707107
       a("tan", PI/4); produces 1
      

A formal parameter can be an address.

Notes:

       1) While in C the first function called is necessarily 'main' in the language ANYFLO any function can be called independently.
       2) The nnn() call causes the search of fff first in the list of commands ANYFLO, then in the list of functions in the memory, then in the files functions of the current directory, then of the environment and finally of the user (it is not necessary to load a function to execute).
       3) functions are automatically compiled and linked to each change in one of them (by default), when loading a file or function when calling a function on the disk also when modifying one of them with the internal editor of anyflo (even in execution mode).
       4) Commands compile and link allow perform these operations on certai functions. Commands no compile and yes compile allow inhibit and restore the automatic compilation.
       5) read func "nom": allows read a function file (overwriting the functions present in memory).
       6) add func "nom": adds a function file to the functions in the memory.
       7) write func "nom": writes on the disk the functions present in memory.
       8) Functions are recursive.
Example:
       factorial(n)
       {
       if (n == 0) return 1;
       else return(n * factorial(n - 1));
       }

       Defines the factorial function recursively.
       $factorial(0); prints 1
       $factorial(3); prints 6
      
See factorielle.func.
Other example Von Koch curve.

Parameter of type function

If a formal parameter is declared as type func immediately after the function name and before the first { it can be called by a command name or function placed between "

Dynamic function

       Functions may be generated dynamically while running. The generate command generate func("ttt") defines and compiles the function whose code is the ttt string. Such a chain can be generated by the program, the programming anyflo then is dynamic (application possible at genetic programming).

Particular functions

       Some algorithms (such as the perspective, 3d textures, light, etc ...) are implemented in a standard way.
       It is possible for the user to implementer itself such algorithmsin language anyflo or in C
Example:
       texture vol(1)="foo"; when viewing volume 1 the function foo will be executed at each display pixel. In such a function the color can be calculated according to the position.
       It is also possible to write such functions directly in the C file utilb.c, see manuel.applic.htm.

Local functions to an object

       It is possible to construct actors, ie objects defined by a program and datas. This is a set of functions (called local) specific to this object and forming a real program (with its own local memory and code) can be executed "in parallel" in different objects.
Syntax: local(0)obj(i)="foo"; adds the local function foo to the local functions of object id. Local functions to define object behavior, they can call each other, and it is also possible to run individually from the outside. (see local) (see manuel.object.htm).

DIRECTIVES

define
include
Conditional compilation
Visibility of a directive

Directive define

#define chaine1 chaine2
       Replaces all occurrences of string1 by string2.
Rermarques:
1) #define D: D is defined but no initialized.
2) write #define D in mode interpreter for conditional compilation.
Example:
a()
{
#ifdef D
$"D is defined;NL;
#endif
}
a(); produces nothing.
#define D;a(); produces "D is defined"
rem("define D")
       Removes the define global D.
rem("define")
       Removes all define global
edit("define")
       Edits all define global

include directive

#include nnn
       Loads file with nnn with a C like syntax:
#include f()
       Loads the text of function f (it must be defined before in the same file or another included before).
Example:
demo0_include.func which includes files:
       include0_define.h where Define_1 and Define_2 are defined.
       include0_externes.func where variables Global_0 and Global_1 are declared extern.
       include0_1.func including:
              include0_2.func
which include function externes() and manipulate variables Global_0 and Global_1.

Conditional compilation

#ifdef D
       If D was defined by:
#define D 1
the code between #ifdef D and #endif is ignored.
#endif
       End of a block of conditional compilation.
Note:
       Conditional compilation is taken into account after a compilation and link:
read func or after:
compile.

Visibility of a directive

       If it is placed in the file header it applies to all functions written in this file.
       If it is placed at the head of function it applies only within this function.

VARIABLES


type
formal
automatic
global
extern
static
visibility
pointer
address
noms
func

Type

       Variables are of dynamic type and are known at definition and then have not to be declared.
as follows:
x="ab cd\tefg\nhijk"; x defined as a variable of type string (string).
x=1.23; x defined as a variable of type float (real number).
x=1,2,3,4,5; x defined as a variable of type array of float.
x="ab cd",[1,5],"AB"; x defined as a variable of type hybride (concatenation of strings and floats).

Size of a variable

It depends on its type:
char: number of characters, for example:
       dim("a bc def") returns 8.
       NP("a bc def") returns 3 (number of words that are separated by a tab a space a comma or a \ n).

float: numbers of flots, for example:
       dim(1,2,3,4,5,6) returns 6.
       NP(1,2,3,4,5,6) returns 2 (number of 3D components).
The editionof a float vector can be done according to a given format:
       edit w prints format 3D by default:
              1 2 3
              4 5 6
edit(w)format(2) prints format 2D:
              1 2
              3 4
              5 6

hybride: number of floats, for example:
       dim(1,"a bc def",2,3,4,5), or NP(1,"a bc def",2,3,4,5) return 3: number of vectors variable sizes which can be obtain by:
       w{0} returns 1.
       w{1} returns "a bc def".
       w{3} returns 2,3,4,5.

Formal variables

       Whose names appear in the function declaration.

Variables automatiques

       Used without declaration in a function, they are unknown to the outside and lose their value at the output of the function.

Global variables

       In an object having local functions local variables are only known in all of these functions..
Declaration: local x;

External variables

       By default, all variables initialized outside of functions (ie directly after the question mark of the interpreter) are known everywhere they are declared extern.
       A variable x may be declared external by writing:
       extern x;
       x is known in any function which contains the same declaration extern x;
Notes:
       rem var "x"; removes variable x.
       name("x")="y"; Rename lvariable x in y.
       ini var; deletes all external variables.

Static variables

       Variables can be declared static in a function (ie unknown outside the function, but retaining their values at the output) by writing:
       static x;
Notes:
       static x=1; declares x static and initializes it at 1.
       static x=(1+2*PI/4); initializes it at a computed value.

Visibility

Variables declared extern, are visible everywhere. A good habit to distinguish them from other variables is to start the name with a capital letter.
Variables declared static in a function are visible only in that function.
Variables declared auto in a function, or undeclared, are visible only in this function.
Variables can not be mistaken as a command assignment would then give rise to an error..

Pointers

The unary operator @ returns an address:
t=[0,5];p=@t; p is the address of t, it is a number:
       $p; prints for example 100023824
while its value is that of t:
       $p[0,5]; prints 0,1,2,3,4

Variables passed by address

A formal parameter can be an address, just declare it address, the call is made with an @.
a(x)
address x;
{
       $x++;
}
x=1;for(i=1,3)a(@x);
prints: (1.000000) (2.000000) (3.000000)

Variable with variable names

var expr1
       returns the evaluation of the variable whose name is the evaluation of expr1.
var expr1=expr2
       gives to variable whose name is the evaluation of expr1 the value expr2.
Examples: var("x",string 123)=-1; gives to variable x123 value -1
for(i=0,3)var("x",string i)=i; generates les 4 variables x0, x1, x2, x3 of respective values 0, 1, 2, 3.
for(i=0,3)$var("x", string i); prints (0) (1) (2) (3)

Function names passed as parameters to a function

       If a formal parameter is declared as type func immediately after the function name and before the first { it can be called by a command name or function in quotation marks.
Example:
Given the function: toto(f,x)
       func f;
       {
       $f(x)
       }

       toto("cos",0); produces 1.0
       toto("sin",0); produces 0.0
Given the function:
anyflo(f,v)
func f;
{
       $2*v+3;
}

toto("anyflo",3) produces 7.0

var func "fff"


       returns the names list of local variables of the function fff.

MATHEMATICAL FUNCTIONS

abs       acos       acosh       alea       arc       ascii       asin       asinh       atan       atanh       atof       atoi
string       stringf       cos       cosh
dist
ent       exp
inclu       input       int       inv
limit       log
max       min       module       average
precision       print       produces       puls
radian       rand       rand2       rand2f       randf
scalar       sin       sinh       sum       sqrt       system
tan       tanh       time       sort
unit
vector

abs(expr): returns the absolute value of expr.
Example:
       $abs(1-3); prints 2

acos(expr): returns the arc cosine of expr.
Example:
       $acos(.5); prints 1.047198 = PI/3

acosh(expr): returns the arc hyperbolic cosine of expr.
Example:
       $acosh(10); prints 2.993223

alea(n): returns the precalculated random index n.

arc(r,an,dan,n): returns the polygonal line radius r, origin angle an, opening dan and n vertices.
Example:
       edit(arc 100,0,PI/2,3); produces
       100.0 0.0 0.0
       70.710678 70.710678 0.0
       0.0 100.0 0.0

ascii(expr): returns string of ASCII code expr.
Example:
       $ascii[65,70]; prints ABCDEF

asin(expr): returns the arc sine of expr.
Example:
       $asin(1); prints 1.570796 e.g. PI/2

asinh(expr): returns the arc hyperbolic sine of expr.
Example:
       $asinh(10); prints 2.998223

atan(expr): returns the arc tangent of expr.
Example:
       $atan(1); prints 0.785398 e.g. PI/4

atanh(expr): returns lthe arc hyperbolic tangent of expr.
Example:
       $atanh(.5); prints 0.549306

atof(expr): returns flot value of string expr.
Example:
       $atof("12.34"); prints 12.340000

atoi(expr): returns the integer value of expr.
Example:
       x=atoi("123"); gives x value 123.000000

string(expr): returns the spring expressing the integer expr.
Example:
       $string(123); prints la chaîne "123"

stringf(expr): returns the spring expressing the float expr.
Example:
       x=stringf(123,45); gives x value "123.45"

cos(expr): returns le cosinus de expr
Example:
       $cos(PI/4); prints 0.707107

cosh(expr): returns the hyperboloc cosine of expr.
Example:
       $cosh(10); prints 11013.233398

dist(p1,p2): returns the distance of 2 points p1 and p2.
Example:
       $dist(0,0,0,100,100,0); prints 141.421356

ent(expr): returns the nearest integer to expr.
Example:
       $ent(12.34); prints 12

exp(expr): returns the exponential of expr.
Example:
       $exp(2); prints 7.389056

inclu(x,w): returns the index of x in w and NIL if x is not in w.
Examples:
       $inclu(3,[1,5]); prints 2
       $inclu(1,2,3,4); prints NIL

input: returns the evaluation of the expression entered at the keyboard.
Example:
       if(input!=NIL) $"OK"; prints OK si on rentre 1 Ne produces rien si on rentre ENTER

int(n): returns the nearest integer less than n.
Example:
       int(1.1,1.9,2); returns (1,1,2)

inv(expr): returns the inverse 3D polyline.
Example:
       edit(inv[1,6]); produces
       4 5 6
       1 2 3

limit(expr): returns le plus petit et le plus grand point de expr.
Example:
       $limit[1,30]; prints (1.0 2.0 3.0 28.0 29.0 30.0)

log(expr): returns the logarithm of expr.
Example:
       $log(10); prints 2.302585

max(expr): returns the largest element of expr.
Example:
       $max[1,12]; prints 12.0

min(expr): returns the smallest element of expr.
Example:
       $min[1,12]; prints 1.0

module(expr): returns the module of expr.
Example:
       $module(100,200,300); prints 374.165741

average(expr): returns the average of expr.
Example:
       $average[1,11]; prints 6.0 < /a>

precision: returns the precision of the operateur ~ (0.1 default)
precision(expr): change precision.

print(expr) or $(expr); prints the evaluation of expr.

produces(expr): returns the produce of the elements of expr.
Example:
       $produces[1,6]; prints 720, ie factorial(6)

puls(x,x1,x2,p,e): returns x1+(x2-x1)*(1+sin(2*PI*x/p-PI/2))^e)/2
Example:
       $puls(.1,-1,1,0,0); prints -0.809017

radian
Angles are expressen in radians: PI radians worth 180 degrees.

rand(expr): returns a no reproductible integer random of [0,expr[.
Example:
       $rand(10,20); prints par example (3.0 15.0)

rand2(exp1,exp2): returns a no eproducible integer of [exp1,exp2].
Example:
       $rand2(10,20); prints par example 12.0

rand2f(exp1,exp2): returns a flottant of [exp1,exp2].
Example:
       $rand2f(1,2); prints par example 1.435683

randf(expr): returns a random float no reproductible of [0,expr[.
Example:
       $randf(1); prints par example 0.124699

scalar(v1,v2): returns the scalar produce of vectors v1 and v2.
Example:
       $scalar(1,2,3,4,5,6); prints 32.0

sin(expr): returns the sinus of exp.r
Example:
       $sin(PI/2,PI); prints (1.0 0.0)

sinh(expr): returns the hyperbolic sinus of expr.
Example:
       $sinh(10); prints 11013.232422

sum(expr): returns the sum of elements of expr.
Example:
       $sum[1,6]; prints 21.0

sqrt(expr): returns the square root of expr.
Example:
       $sqrt(2); prints 1.414214

system("ccc"): invokes the command processor to execute command ccc.
Example:
       system("date"); produces la date

tan(expr): returns the tangent of expr.
Example:
       $tan(PI/4); prints 1.0

tanh(expr): returns the hyperboloc tangent of expr.
Example:
       $tanh(.5); prints 0.462117

time: returns the time (number of seconds) elapsed since thelaunch of the programm.

sort(expr): returns the list sorted in ascending order of expr.
Example:
       $sort(10,1,3,7); prints (1.0 3.0 7.0 10.0)

unit(v): returns the unit vector of v.
Example:
       $unitaite(100,200,300); prints (0.267261 0.534522 0.801784)

vector(v1,v2): returns the vectorial product of vectors v1 and v2.
Example:
       $vector(1,2,3,4,5,6); prints (-3.0 6.0 -3.0)

INPUTS OUTPUTS

direct
formated

input: returns the evaluation of the expression entered at the keyboard.
print(expr); or $(expr); prints the evaluation of expr.

Direct

       write(expr) name("A"); writes in file A the evaluation of expr.
       x=read("A"); gives to x the content of file A.
Note:
       If expr is a string A is an ASCII file
       write(expr) ascii name("A"); writes in ASCII file A the ASCII expression expr.

Formated

format("<descr>string")
       Converts expr according to the description descr whose format consists of a list of characters separated by commas:
       *: ignored format.
       numerical value: value forced.
       X: converted value.
Example:
       x=" coordinates 1.2 3.4\n coordinates -1.2 10\n";
       y=format("<*,X,X,0.0>",x); returns vector:
       (1.2,3.4,0.0,-1.2,10.0,0.0)