Prior to the discussion of the fundamental characteristics of the language we will show how to write our first Biferno script. We assume that both the Web server and Biferno have been correctly installed (see the "Biferno: Installation and Administration Guide" document). The example will help the reader familiarizing with the language basic syntax, the use of variables, functions and classes.
A Biferno script can be written using any text editor. To start, open a new text file and save it with the ".bfr" extension, e.g. "hello.bfr". It is best to insert the opening and closing tags for the Biferno code at this stage, before writing any code. Finally write a simple instruction between the tags:
<?
print("Hello world!")
?>
The file containing the newly created script must be stored in a directory where our web server can access it. The script can now be executed by requesting our Web server to serve the script file. This is done by pointing our browser to the URL that locates the script file on our Web server. If we have executed these steps correctly the browser window will return the following result:
Hello world!
For sake of simplicity we will refer to the content of the browser window as the output of the Biferno script. Notice that the actual output of a Biferno script is the HTML page produced by the script, which is returned by the Web server to the browser using the HTTP protocol.
In the example above we used the pre-defined print function that allows to
print (insert on the Biferno script output) the value of a variable, a
constant, or the result of an expression. Instead of the print keyword it is
possible to use the dollar symbol $ as in:
<?
$"Hello world!"
?>
Using the dollar symbol before and after a variable name, its value can also
be printed outside of the Biferno code delimiters. This is shown in the
following example, where the val parameter is passed to the "newpage.bfr"
page and takes the value of the myString variable, which is output on the
HTML page using the $ symbol set before and after the variable name. The
delimiter tags of the Biferno code are not used. The next row of code shows
an alternative manner of obtaining the same result using the print function.
<? myString = "Ciao" //String class variable initialization ?> <html> <body> <? print(myString) //Print the value of the myString variable $myString //Same effect as previous instruction ?> <br> <a href="newpage.bfr?val=$myString$">New Page</a> <a href="otherpage.bfr?val=<? print(myString) ?>">Other Page</a> </body> </html>
In this and the other examples that we have shown we also have introduced
comments. As in the C language, comment are introduced by the // string
(comment spanning a single rows) or enclosed between the /* and */ strings
(comment spanning multiple rows).
Whitespace and tab characters are ignored by the Biferno interpreted. They
play a role in visual formatting of the source code and make it more easily
readable. In our examples we will always use spaces to separate identifiers,
operators and values, tab characters to indent blocks of code reflecting the
code structure, and carriage return characters to indicate the end of a line
of code. The end of a line of code in Biferno can be also indicated by using
the ; character.
In the following chapters we will describe in more detail the various elements of the language (variables, operators, classes, functions, and so on).
When two dollar characters ('$') are used to print outside the Biferno
tags, the two charcters must either be on the same row, or the ";"
character must precede the second "$" character. If this is not the case,
all text between the two dollar characters will be regarded as regular HTML
text.
When a single '$' characters is used to print inside the Biferno tags the
interpreter will print the text between the "$" character and the first
following carriage return or ";" character (assuming the text is a legal
variable name).