In the following you will be guided through the process of making a very simple example program. This will probably give a good first impression of the language.
It is assumed that you have successfully compiled the package at this point as well as having the bcompiler and bruntime executables ready to run. If this is not the case please consult Installation section of the manual.
Now its time to pick the texteditor of our choice and start editing a sourcefile. The classic example of the first program in any language is the famous "Hello world" application. This program will not do anything more than just printing out a line saying :
Hello World |
// // Hello World Program // // main function void main () { prs ("hello world"); nl (); } // required declarations */ void prs (string s); void nl (); |
The definition of the function "main"
The declaration of the function "prs"
The declaration of the function "nl"
The difference between definitions and declarations of functions is crucial. In order to invoke any function, it must be at least declared. Attempts to invoke a function that is neither defined nor declared will fail at the early type-checking stage of compiliation. A function that is only declared but not defined in a given sourcefile needs to be defined in another place. In order to pass the above mentioned type-checking stage of the compiler successfully the functions and the types or arguments they expect must be known somehow. This is why declarations are needed in the above case. In order to perform our task we need to make use of two externally defined functions already. These correspond to the 2 declarations in the sourcecode.
Now save the file to disk and name it for example "hello.bf". On your commandline then invoke the bcompiler executable like this:
bcompiler hello.bf |
bruntime hello.out |
$ bcompiler hello.bf $ bruntime hello.out hello world |
In the example directory you will find more simple examples, which will demonstrate most basic features of the language. For a more in depth look at the language syntax and constructs proceed with reading this manual.