Langage

De Wiki1000

Sommaire

Overview

The line 1000 language is a managed language which inherits from object Pascal.

Main differences between Line 1000 and Object Pascal are list below :

  • They is no supports to define types, classes and structures because this part must be done at the Model level.
  • There is no support for SET types and operators
  • The memory is managed so there is no need to explicitly allocate or free memory.

Language features

Block of code

A block of code has the fallowing structure :

declarations ;
begin
  instructions ;
end;

declarations may be variable, procedure or function declaration.

Variables

Variables MUST be explicitly declared using the fallowing syntax :

var 
  identifier : type;
  identifier, identifier : type;
  identifier : Array[0..X] of type;
  identifier : Array of type;

Types

The language supports strong type declaration and compiler check for type integrity; nevertheless, for compatibility reasons, type checking generate warning message and not errors.

type alias(*) remarks
integer int,unsigned,short,long,unsignedlong 32 bit signed integer
longint 64 bit signed integer
double float double precision float
currency decimal currency fixed point 4 decimals
boolean logical type
string anyURI AnsiString (**)
char Character
enum Enumeration
TDatetime datetime Date and time encoded as double
date Date encoded as double
time Time encoded as double
variant Variable container with dynamic type information
TClass Generic class type
TObject Generic object type
TPersistent Generic persistent type

(*) Alias are defined to support SOAP serialization

(**) String encoding may be dependent of the Line 1000 release, until and including release 5.60 the string encoding is Ansi based. In the future the string encoding may be unicode based.

These types are defined to support SOAP serialization :

type alias remarks
normalizedString
token
duration
base64binary Binary base 64 encoded stream
hexbinary Hexadecimal encoded stream

Literals

Constants

There is no support at this time to declare constant inside a code block.

integer 10
hexadecimal $0A
float 1.00
char 'A'
char #10
string 'This is a string with a quote'

Procedures and functions

Like in Pascal language procedures and functions may be embedded inside a code block :

var
  p1,p2,p3 : type; 

  function name(p4:type):type;
  var p2:type;
  begin
    Result := p1+p4+p2;
  end;

begin
  ...
  p3 := name(p1,p2);
end;

Operators

Arithmetic

+ Addition
- Subtraction
unary (-) Negation
/ Division
* Multiplication
div Integer division
mod Integer modulo

Logical

and logical AND
or logical OR
xor logical XOR
not Negation

Comparison

= equal
<> not equal
> upper
>= upper equal
< lower
<= lower equal

Expression

Expression are evaluate left to right, each term must be parenthesized :

  (a=b) and (c=d) ....

Expression evaluation are optimized :

  // term is not evaluate.
  false and term

  // term is not evaluate.
  true or term

Instructions

Statement

Statements are delimited by semi column ";"

  x := 1;
  y := 2;
  x := x+y;

Several statements may be combined in a single statement using begin / end :

  begin
    x := 1;
    y := 2;
    x := x+y;
  end;

Assignment

Assignment used the := operator :

  x := 1;

for

The for instruction allow implementation on index based loop :

  for index:=lower to upper do 
   statement ;

  for index:=upper downto lower do 
   statement ;

The index variable MUST BE an integer variable.

while

The while instruction allow implementation of expression based loop :

 while (expression) do
   statement ;

repeat

The repeat instruction allow implementation of expression based loop :

 repeat
   statement ;
 until (expression)

Unlike while construction the repeat statement will be executed at least one time.

foreach

The foreach instruction allow iterations inside a collection :

  foreach V in C do 
   statement ;

C MUST be a collection V MUST be a variable of the collection type

break

The break instruction allow exiting a loop, it can be used in any loop construction.

  for index:=lower to upper do 
   begin
     ....
     if expression then break;
   end;

The effect of the break instruction is to exit the loop.

Break instruction could be used inside for, while, repeat, foreach loop instructions.

continue

The continue instruction allow resuming a loop, it can be used in any loop construction.

  for index:=lower to upper do 
   begin
     if expression then continue;
     ....
   end;

The effect of the continue instruction is to branch at start of the loop.

Continue instruction could be used inside for, while, repeat, foreach loop instructions.

if

The if instruction allow implementation of test and branch :

  if expression then statement ; 

  if expression then statement else statement ; 

case

The case instruction is not supported at this time.

Exception support

Exception may be rise easer by managed code or by runtime and framework code. In both case the exception may be trap and managed using the try / finally / except construction.

Rising an exception

The rise instruction allow rising an exception :

  rise ERule.Create('some message here');

The exception type MUST be of the fallowing class :

  • ERule

Try / finally block

The Try/finally block construction may trap an exception to ensure execution of an exit code :

 try
   statement 1;
 finally
   statement 2;
 end;
 statement 3 ;

if an exception occurs in statement 1 the execution flow will branch in statement 2 and then exit from main block; the statement 3 is not executed.

Try / except block

The Try/finally block construction may trap an exception to manage the exception :

 try
   statement 1;
 except
   statement 2;
 end;
 statement 3;

if an exception occurs in statement 1 the execution flow will branch in statement 2 and then continue in statement 3.

The exception message may be catch and used in the exception block :

 try
   statement 1;
 except
   on E:Exception do 
    begin
      ... do something with E.Message ....
      statement 2;
    end;
 end;
 statement 3;

Inside an exception block the exception may be re-trigger :

 try
   statement 1;
 except
   statement 2;
   raise ;
 end;
 statement 3;

if an exception occurs in statement 1 the execution flow will branch in statement 2 and the exception will be re-rise; the statement 3 is not executed.

Magic functions

Assign()

TP()

Outils personnels