LARP

LARP pseudo code language

This section presents LARP's pseudo code language. The language is flexible and intuitive, allowing one to easily formulate algorithms.

This first example illustrates the syntax of pseudo code instructions in LARP. It displays on screen the character string Hello world!

\\ Very simple pseudo code!
START
    WRITE "Hello world!"
END

A LARP algorithm must start with keyword START. This instruction indicates where the algorithm's execution starts. The following instruction (in the above example, WRITE "Hello world!") is the first instruction to be executed. Reciprocally, the END iinstruction indicates where execution ends.

Pseudo code syntax

As any programming language, LARP provides a set of instructions allowing one to formulate algorithms as pseudo code. These instructions may accept one or more arguments and their syntax corresponds to one of the following formats:

instruction arg1, arg2, ...

or

instruction (arg1, arg2, ...)

The examples below use the WRITE instruction to display results in the execution console. A single WRITE instruction can produce several results:

\\ Example of instructions
START
    Result = MAXIMUM(12, 2, 9)
    ÉCRIRE "Maximum = ", Result
END

As noted in this example, WRITE instructions adopt the first form of syntax while MAXIMUM instructions adopt the second form.

Polymorphic contextual language

Unlike most traditional programming languages (such as C++ and Java), LARP is polymorphic contextual. This term means that a LARP algorithm does not have to explicitly define its variables prior to using them. This programming philosophy is frequently found in scripting languages such as Perl and Lisp. Since the type of a variable depends on its contents and this contents may vary during the execution of the algorithm, so does its type.

LARP supports integer and real values, character strings and containers (grouping values of various types):

\\ Smarter pseudo code
START
    Data = [12, 2, 9]
    WRITE "Maximum = ", MAXIMUM(Data)
END

Inputs/outputs

LARP’s language provides instructions for reading data (READ) and for writing results (WRITE). These two instructions interact with the execution console to allow an algorithm to read data from the keyboard and display results on screen:

\\ Pseudo code adding two values
START
    WRITE "Enter two numbers: "
    READ N1, N2
    WRITE "The sum of", N1, "and", N2, "is", N1 + N2
END

One instruction (QUERY) even allows to write a query and read the answer in a single instruction.

Conditional and iterative structures

LARP supports many conditional structures (IF, IF-ELSE, IF-ELSE-IF, SELECT) and iterative structures (WHILE, REPEAT-UNTIL, FOR) found in traditional programming languages:

\\ Pseudo code computing the mean of values read
START
    \\ Read the number of values to process
    REPEAT
        QUERY "How many values to process?", Nb
    UNTIL Nb >= 0

    \\ Are there values to process?
    IF Nb > 0 THEN
        \\ Read values and compute their sum
        Sum = 0
        FOR I = 1 TO Nb DO
            QUERY "Enter one value? ", Value
            Sum = Sum + Value
        ENDFOR

        \\ Display mean of all values
        WRITE "Average =", Sum / Nb
    SINON
        WRITE "No value to process"
    ENDIF
END

Modular programming

Modular programming is a technique used to create complex algorithms. It consists in splitting a complex algorithm into smaller ones. Each small algorithm, written as pseudo code or flowchart, is called a module and carries out a simple task. All modules within an algorithm cooperate in order to perform the algorithm’s tasks.

\\ Main module
START
    READ Value
    WRITE 'Factorial of', Value, 'is', Factorial(Value)
END
\\ Auxiliary module FACTORIAL
ENTER X
    IF X = 1 THEN
        Res = 1
    ELSE
        Res = X * Factorial(X-1)
    ENDIF
RETURN Res

Files and input/output buffers

By default, during execution an algorithm reads data through the keyboard and produces results in the execution console (i.e. the screen). The keyboard (for inputs) and the execution console (for outputs) are said to be standard input/output interfaces in LARP.

LARP is also able to process data retrieved from external documents and/or store data into such documents. It supports two external sources of information:

  • Input/output buffers: data storage integrated to a LARP project. Such buffers allows to read and/or write directly in a document inserted into LARP project. As for modules, input/output buffers are identified by an unique name and listed in the document browser.
  • Files: data storage generally located on the computer’s hard disk (or on any peripherical device accessible through the computer’s file system). Files are identified with a unique name in the file system of the computer running LARP.
\\ Main module
START
    \\ Open a buffer to be read from through a channel (3)
    OPEN BUFFER "DATA" ON 3 IN READMODE
    \\ Open a file to be written to on a channel (5)
    OPEN FILE "C:\\RESULTS.TXT" ON 5 IN WRITEMODE

    \\ Transfer data from buffer to file
    WHILE NOT ENDOFCONTENT(3) DO
        READ Value FROM 3
        WRITE Value IN 5
    ENDWHILE

    \\ Close opened documents
    CLOSE 3, 5
END

The above pseudo code algorithms provide an overview of LARP's programming language syntax and functionalities. To have a thorough description of its programming language, see LARP's online documentation (also available on the Web). Note that all pseudo codes presented in this page may also be written as flowcharts.