Tutorial
26 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
26 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

Discovering FBSL By a beginner for beginners FBSL (Freestyle BASIC Language Script) © 2001-2008 by Gerome GUILLEMIN, Mehdi BOUAZIZ and Mike LOBANOVSKY Contents Introduction 8. Types and classes 1. Basics Definition of a type of data item First steps A type can in hiding another To calculate with FBSL Classes and methods 2. Data and variables Inheritance Assignment Similarity and uniqueness To display the value of a variable Overloading operators Reassignment 9. Meta-directives Multiple assignments Definitions (#Define) Operators and expressions Declarations (Declares) Composition Macros 3. Supervise implementation 10. Creating executables Flow Control Conclusion Repetitions in loop 4. Principal types of data Numbers Character strings Arrays 5. Procedures and functions Procedures Local variables and global variables Functions Default values for the parameters Optional parameters Passing arguments by value or by Reference 6, graphic interfaces (GUI) To display a message box To communicate with the computer To open a window A basic example of application 7. Files Using Files Working with files. Include files Namespaces 1Introduction These basic lessons are intended to introduce FBSL. They are directed towards beginners and hopefully ...

Informations

Publié par
Nombre de lectures 17
Langue English

Extrait

Discovering FBSL
By a beginner for beginners





FBSL (Freestyle BASIC Language Script)
© 2001-2008 by Gerome GUILLEMIN, Mehdi BOUAZIZ and Mike LOBANOVSKY


Contents
Introduction 8. Types and classes
1. Basics Definition of a type of data item
First steps A type can in hiding another
To calculate with FBSL Classes and methods
2. Data and variables Inheritance
Assignment Similarity and uniqueness
To display the value of a variable Overloading operators
Reassignment 9. Meta-directives
Multiple assignments Definitions (#Define)
Operators and expressions Declarations (Declares)
Composition Macros
3. Supervise implementation 10. Creating executables
Flow Control Conclusion
Repetitions in loop 4. Principal types of data
Numbers
Character strings
Arrays
5. Procedures and functions
Procedures
Local variables and global variables
Functions
Default values for the parameters
Optional parameters
Passing arguments by value or by Reference
6, graphic interfaces (GUI)
To display a message box
To communicate with the computer
To open a window
A basic example of application
7. Files
Using Files
Working with files.
Include files
Namespaces




1Introduction

These basic lessons are intended to introduce FBSL. They are directed towards beginners and
hopefully they will enable them to become familiar with, and, to use the basics of this straightforward
and powerful language.
FBSL means “Freestyle BASIC Language Script”. Like many modern programming languages
contains flavours of Visual BASIC, QBasic, PHP, Pascal and C++.
It is a kind of hybrid language hence the “Freestyle”.
It is especially designed for the win32 platform (Windows 95 SR2 to Windows VISTA).
It is compatible with, and completely functional under, LINUX Wine.

Do not hesitate with to download the last version of FBSL.
And to join the forum if you have questions, suggestion about FBSL, or even criticisms… of this
document.

Remarks on the presentation of the document :
The code with a pale yellow background contain complete scripts which one can
copy/paste into a text editor and save with the extension .fbs.
You can then execute the program by a doubleclick on the icon or directly from the editor
if it allows (Eclecta is one such editor)
The code fragments with a pale blue background contains pieces of code intended to be
analysed and/or inserted in complete scripts to be able to test them.
The diagrams with a black background represent the result of script As it seen on the
screen.

Contents





















2
Chapter 1. Basics
This chapter demonstrates the fundamental knowledge needed to write your first program in FBSL.

First steps
We will start exploring FBSL using the “console” mode. Scripts can be written in any text editor that
gives plain text “notepad.exe” for example. But the FBSL distribution offers more specialised editors,
in the standard installation look in "C:\Program Files\FBSLv3\Samples" and select sub-directories
starting with IDE.

You can also launch 'FBSLv3 Editor (Eclecta Editor)' from start/Programs/Freestyle BASIC Script
Language. Then click on File/New or on in the bar of icon:



On the first line type: #apptype console to tell FBSL this one will use the console mode.
then type: pause, this prevents the console closing immediately.

This first script does not do anything in particular it is only to open one console.



Contents








3
Now on click on Compile and Run Script or simply press on the <F5> key, you get the following
window:


Press the <Enter> key, and the console is closed.

The console mode is useful for testing small fragments of code, algorithms and writing small utility
programs.

Always insert your code between #App Type Console and Pause







←Enter your code here






From here on we will use the Console mode quite extensively to demonstrate How to use FBSL

Contents










4To calculate with FBSL

FBSL can evaluate all the basic arithmetic operations.

Symbol Operation
+ Addition
- Subtraction
* Multiplication
/ Division
^ Exponentiation

Turn on the editor now and test this:

print 5+3
print 2-9
print 7 + 3 * 4
print (7+3) * 4
print 20/3


Do not forget to insert these lines between #AppType Console and Pause.

The command print displays rest of the line on the screen.

Note that spaces are optional between the figures and the operators (the editor adds automatically
spaces to make the code more readable) but space is essential between the command print and
what follows.

Click on Compile/Run Script or type on <F5> , you obtain the following window:


Contents









5Here an example of this script with accompanying notes:










(a


(b






(c


(d

(e





(f

(a Indicates that the application is to be of type “console”
(b The print instruction causes the following characters to be displayed on the console.
(c Causes the program to wait for the Enter key to be pressed.
(d enclosed in quotes you can print the operation code in front of the result.
Characters in quotes are printed “as is”, that is, literally
(e Remark
- Literal text is typed between quotation marks
- The elements of the post (quoted part, calculated part) are separated by commas
(f prints a blank line. The colon “:” indicates a separate instruction

Note that characters which are typed after the apostrophe (') are comments and are ignored by FBSL
when the program is executed.
They make it possible to explain in plain language what the instructions do and can also contribute to
the legibility of script by separating the various sections from the program.

The comments can also be preceded by a double oblique bar // instead of the apostrophe. One
can also write comments on several lines, which will form a block framed by /* at the beginning and
*/ at the end.

It is a good idea to comment anything that is a bit unusual or complicated; it is surprising how quickly
one forgets.

Blank lines can be used between lines of code to make it easier to read

It is possible to write several instructions on the same line by separating them by : (colon).

Contents
6
FBSL performs calculations following a hierarchy of operations.
The acronym PEMDAS: is a useful mnemonic to help memorise the order of priority for calculations

- P for parentheses. This is the highest priority. Any calculations surrounded by parentheses
are performed first. This makes it possible to ensure that calculations are performed in the
required sequence
2* (3-1) = 2*2 = 4 FBSL → ? 2 * (3 - 1)
(1+1) ^ (5-2) = 2^3 = 8 FBSL → ? (1 + 1) ^ (5 - 2)

- E for exponentiation. This is evaluated before other operations
2^1+1 = (2^1) + 1 = 3 and not 4 FBSL → ? 2 ^ 1 + 1
3*1^10 = 3 * (1^10) = 3 and not 59049 FBSL → ? 3 * 1 ^ 10

- M and D for multiplication and division, which have the same priority.
2*3-1 = 5 and not 4 FBSL → ? 2 * 3 - 1
2/3-1 = -0.3333 FBSL → ? 2/3 – 1

- A and S for addition and subtraction, which are carried out last

- If two operators have the same priority, the evaluation is done from left to right.
59*100/60 = 5900/60 = 98.3333 FBSL → ? 59 * 100/60

? is a short cut for print. There is also another synonym of print: echo which means the same thing.

The syntactic flexibility of FBSL makes it a rich language and makes it easy to convert between other
programming languages to FBSL, and, from FBSL to other programming languages.

Contents

















7Chapter 2. Data and variables

A computer program mainly handles data. The program accesses this data using “variables” of
various types. A variable generally consists of a variable name which the computer uses as a
reference to the address in memory that contains the actual data.
At this address one value is stored, it is data itself. That could be a number, a character string, an
array, a user defined type (UDT) etc.
Variable names can be freely chosen,

  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents