LDPL Source Code Structure
LDPL is a case-insensitive language. This means that variables and statements
that consist of the same characters are understood to be the same variable
or statement regardless of their case. For example, in other languages the
FOO would represent two different variables, but in
LDPL they are the same one. This same thing happens with statements. For
LDPL it's the same if you write
dIsPlAy (but please don't do so).
LDPL is case-insensitive only for latin A-z characters. Accented characters and
non-ASCII letters will be matched in a case-insensitive manner. Depending
on the LDPL implementation,
ÁÁÁ may not represent the same
identifier. It is good practice to write your code in a single case and
always call your variables and functions by the exact name used when
Comments in LDPL are denoted with a hash symbol ('#') and can be placed both on their own line or at the end of a line that already contains a statement. Everything after the hash is considered to be part of the comment and, therefore, not executed.
1 2 3 4 5
Data and Procedure Sections
LDPL was designed to be a rigidly structured programming
language and, as such, variable declarations and the remaining code procedures
are separated into two different, mutually exclusive sections within every
source file: the
data: section and the
1 2 3 4
Variable declarations should be placed within the data section, while the rest of the code should be placed inside the procedure section. Further sub-procedures should be placed also within the procedure section, inside their own sub-procedure subsections.
The data section may be obviated if no variables are used.
If your project consists of multiple LDPL source files, each file must have its own data and procedure sections.
Including More Source Files
You can import other LDPL source files to your LDPL source by using the include statement. For example, say you have two sources:
1 2 3
1 2 3 4 5
You can import the second source into the first one in order to create one big source file like this:
1 2 3 4
When you run the code above, it will print
using the sub-procedure
someSubprocedure included from the second file.
The location where the included files are searched for is relative to the file that includes them. You may include as many files as you like.
include statement can only be used before the data section.
LDPL source code can be extended using C++ Extensions, C++ source files
that can be compiled along the C++ source code generated by the LDPL compiler.
While these are explained in greater detail in their respective section of
this document, two statements are relevant to this part of the documentation:
C++ Compiler Flags
When writing C++ code, you may need to pass some flags to the C++ compiler.
Say, for example, you are writing something using the SDL Library. When
trying to compile your code, you will need to pass the flag
-lSDL to your
C++ compiler. This same thing can be achieved under LDPL by using the
Following the example above, if you want to pass the flag
-lSDL to the C++
compiler that compiles the code generated by the LDPL compiler from your LDPL
source code, you may do this:
1 2 3 4 5 6
Often, different operating systems require different flags. In those cases,
you can restrict the
flag statement to a particular OS:
1 2 3 4 5 6 7 8
LDPL officially supports the following operating systems:
And includes experimental support for these fine systems:
flag statement can only be used before the data section.
C++ Extension Including
Extensions are C++ source files that you can compile along your LDPL source
in order to extend the language, as stated above. If you want to include an
extension, you may use the
extension statement. For example:
1 2 3 4 5 6
extension statement can only be used before the data section.