FreeBASIC

Free Basic (short FB ) is a free, open - source compiler whose syntax is based on Microsoft QuickBasic. It allows the generation of 32 -bit software applications, games, etc. for Microsoft Windows, Linux, FreeBSD, and DOS, partly for the Xbox. Versions for other operating systems is planned.

C compatible libraries can be used in part in Free Basic directly, C libraries after all. For example, GTK , GSL, SDL, Allegro, Lua or OpenGL can be used, and with each new version, increases the number of supported libraries.

The first version was released in November 2004.

  • 3.1 Hello World
  • 3.2 Object-Oriented Programming
  • 4.1 FBIde
  • 4.2 FBEdit

Features

  • The Free Basic compiler ( " FBC " ) generated assembler code that is compiled with the GCC suite, and linked. This also libraries of the GCC suite can be used and obtained binary executables smaller size for Windows, DOS and Linux. A corresponding compiler option, it is for example also possible to generate code C ( so-called " backend C " in contrast to the " back-end assembly ").
  • Inline assembler
  • Pointers to variables and functions
  • Overloading of functions, subroutines (functions with no return ), and operators. In addition, functions and subroutines can be created with optional parameters.
  • In contrast to the DOS-based QuickBasic can draw on almost all features that utilize today's programmers, such as the WinAPI and other (C -compatible ) libraries.
  • All functions (among file access, strings, etc.) of the runtime library, as well as all internal graphics commands are platform-independent, ie can be used on Windows, Linux and DOS alike. This allows to easily write cross-platform applications.
  • Call options ( " bindings" ) for many popular (graphic ) libraries, including OpenGL or DirectX.
  • Shorthands, macros, etc., remove the programmer some typing
  • Fundamentals of object-oriented programming such as classes ( "types " ), as well as the single inheritance (some features, such as interfaces, or the keyword "class " instead of "type" are already being considered, but have not yet been implemented ).

Syntax

There are currently over 400 keywords that can be used in some cases to mehrerlei way. In general, three types of keywords can be distinguished:

  • Instructions: instructions perform a specific task, such as the output of text on the screen.
  • Functions: they are characterized by the fact that after it is called a value is provided, which is the result of the function call. The value can be the only meaning of the function ( for example in mathematical functions such as LOG) or only on the status of the function call information (functions with instruction character as GetMouse, this function queries the state of the mouse and returns a number that confirms that the query was successful or if there was an error ).
  • Clauses: They influence the behavior of statements and functions and can not be used in isolation from them.

The upper / lower case is, as usual, BASIC, without meaning. " GetMouse " and " GetMouse " are treated the same by the compiler.

Variables

When dealing with values ​​( numbers, strings, or other types of information ) variables and constants are used STRING variables (strings ) are enclosed in double quotes " " ". If the string is preceded by a "! ", Can also escape sequences be used. (eg print "Hello \ NWorld " - creates a line break between " Hello " and " World ") Using these variables and constants can be used across different operators for numbers, variables about various mathematical operators are. available ( , -, *, /, LOG, EXP, SIN, ASIN, ...) With STRINGs however, the selection of operators is limited, is possible only the concatenation ( or & ) and indexing (using square brackets ). .

Functions and subroutines

It is also possible to create your own commands in a program consisting of a series of existing commands. Such a separate command can be a SUB (short for subroutine ) that such a statement acts, or a FUNCTION that can as well as Free Basics own functions return a value. Both can work with parameters that may be optional. It supports analogous to C and variable parameter lists.

Unlike many other languages, program commands are not terminated with a semicolon, but with a newline as well as in QBasic. If you want to extend a command over multiple lines must end each line that does not end the command, underscore are written:

PRINT " Hello, this string " _ " Is a single string. " Multiple commands can be strung together without line break by a colon:

PRINT " Hello, this string ": PRINT " is a single string. " Another difference from other languages ​​is that when calling subroutines which bracketing is optional because you can call a subroutine with both subroutine (parameters) as well as subroutine parameters. This property is also derived from QBasic. However, this is not possible with functions, there brackets must always be set.

Code examples

Hello World

A simple hello world program in Free Basic looks like this:

PRINT " Hello world!" SLEEP PRINT here is an instruction that causes a text is displayed on the screen. "Hello world! " here is a parameter; in this case, is hello world! displayed on the screen. SLEEP command is not required. It is only used to prevent the output window of the application closes automatically if it has not started from the console.

Object-Oriented Programming

' Vector class Type Vector W as Integer H as Integer Declare Constructor ( nW as Integer, nH as Integer ) end Type   Constructor Vector ( nW as Integer, nH as Integer ) W = nW H = nH end Constructor   ' Class to create an object Type AObject Private: X as Integer Y as Integer Movement as vector pointer Public: ' Public Methods including a constructor and a destructor Declare Constructor ( nX as Integer, nY as Integer ) Declare Destructor () Declare Sub SetMotion (Motion as Vector Pointer) Declare Sub Move () Declare Property GetX as Integer end Type   'Set initial values Constructor AObject ( nX as Integer, nY as Integer ) X = nX Y = nY end Constructor   Sharing 'in allocated memory Destructor AObject () delete Movement end Destructor   'Set motion vector Sub AObject.SetMotion (Motion as Vector Pointer) Movement = Motion end Sub   Move ' the object by its motion vector Sub AObject.Move () X = Movement -> W Y = Movement -> H end Sub   ' Return of X, which would otherwise be inaccessible Property AObject.GetX as Integer Return X end Property   'Here the actual program starts   'Create a new instance of' AObject ' at coordinates 100, 100 Dim player as AObject = Type (100, 100)   ' Allocate a new vector object dynamically and move its position by 10 to the left and 5 down Player.SetMotion ( new Vector ( -10, 5) )   ' Update ' The position of ' Player Player.Move ()   'Display the new value of X ( 90) Print Player.GetX   ' Because ' player ' is a local variable, its destructor is automatically called at the end of scope ( "scope " )   ' Wait Before end of the program by pressing Sleep IDE

In addition to the support from well-known development environments, such as Geany, there are also two specially designed for FreeBASIC editors:

FBIde

The FBIde is a lightweight editor and the oldest IDE for FreeBASIC. The current version is 0.4.6r4.

FBEdit

More options provided by the Free Basic Editor, short FBEdit. There is a separate interface for the design of dialogues using resource files and the Windows API. The current version is 1.0.7.6c of 6 July 2010.

328156
de