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).
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: # This won't be executed # This won't be either procedure: # This line won't be interpreted
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
data: # Variables go here procedure: # The rest of the code goes here
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
# This is 'firstSource.ldpl' procedure: call someSubprocedure
1 2 3 4 5
# This is 'includedFile.ldpl' procedure: sub someSubprocedure display "Hi there!" end sub
You can import the second source into the first one in order to create one big source file like this:
1 2 3 4
# This is 'firstSource.ldpl' include "includedFile.ldpl" procedure: call someSubprocedure
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
flag "-lSDL" flag "-fpermissive" # you can pass as many flags as you want data: #... procedure: #...
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 "someDirectory/someFile.cpp" flag "-O3" data: #... procedure: #...
extension statement can only be used before the data section.