en:presentation

Ceci est une ancienne révision du document !


The W language is a procedural, loosely typed language with flexible and powerful data structures.

Comments are written after the semicolon (;). They can appear either alone on a line or at the end of a line after an instruction. Empty lines are considered comments.

; First comment
 
; Other comment
 
; That's it!

The W language supports only ONE instruction per line, except for the comment, which can appear at the end of the line after the instruction. A program consists of the start instruction, the code with the processing block and the exception block, and a finish instruction. In each line (= instruction), the different elements of the instruction are separated by at least one space (space, tab). Accepted line breaks are those in Unix and Windows formats, interchangeably. Comments can be written anywhere as indicated above. Each program can call subroutines, called sub, as well as another program which in this case is called a library (or library). The language's distinctive feature is that its syntax mandates a processing block and an exception block in each program and subroutine. During execution, any exception automatically causes a jump to the beginning of the exception block of the current program or subroutine. This is the equivalent of a systematic “try/catch” loop. Let's revisit the classic Hello world example: <code w hello.w> ; classic example…

begin hello ; start instruction, marking the beginning of the main block

; processing block

echonl “Hello world!” ; the echonl instruction allows writing to the console, with a line break

; Here, the process skips to the end (end) except ; instruction marking the beginning of the exception block

; exception block end ; end of the hello program

At runtime, the process starts at the beginning instruction of the main block, then executes all instructions up to the except instruction. At that point, the process goes directly to the end instruction and then terminates. The second possible start instruction is 'background <name>': the process works identically to that with 'begin', except that the process runs in the background, and therefore returns control immediately. In this mode, all writes and reads from the console are automatically inhibited by the executor. The third and final possible start instruction is 'library <name>(<parameters>)'. It allows the program to be called from any other program or library, but the library cannot be the first program launched. During the call, the library is loaded on the fly at runtime only.

The include statement allows you to include another source in the current source stream. Recursion is not allowed and will throw an exception.

The source file to be included must be located in the WSRC directory.

<code w> include “calcul.w”

Library and method calls are made using the do call invoke instructions:

* Library call, external to the current source code: call <library name>(param1, param2, …), library written in W, main block of type library, and available in the WBIN directory in compiled mode or WSRC in interpreted mode

* Module call, plugin type: invoke <module>&<function>(parameter), written in C and whose binary is located in WBIN

* Object sub/method call: do <var>(param1, param2, …), written in W and declared in the same source code as the current source code (including include files) All passages of Parameters are passed by reference: in called subroutines, access to variables acts on the original variable.

Variables must be declared, but without a type, and can be declared anywhere in the code. They only become usable after their declaration; otherwise, an exception will be thrown.

<code w> ; declaration of 3 variables declare x, y, tmp

The typing of each variable is done when it is assigned. There are 7 usable types:

* Null: a declared but unused variable

* Number: a fixed-point number with 13 digits before the decimal point and 5 decimal places

* Dynamic: stores structured strings or any binary content * Hashtable: a key/value map, where each value is itself another variable from among the available types, including Hashtable

* Subroutine: stores the address of a subroutine

* Object: identical to Hashtable and allows storing/managing classes and objects

  • en/presentation.1766593947.txt.gz
  • Dernière modification : 2025/12/24 16:32
  • de root