Skip to content

Latest commit

 

History

History
171 lines (125 loc) · 5.28 KB

structure.md

File metadata and controls

171 lines (125 loc) · 5.28 KB

LDPL Source Code Structure

Case Sensitivity

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 variables foo and 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 or dIsPlAy (but please don't do so).

!!! warning 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, ááá and ÁÁÁ 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 declaring them.

Comments

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.

:::coffeescript
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 procedure: section.

:::coffeescript
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:

:::coffeescript
# This is 'firstSource.ldpl'
procedure:
    call someSubprocedure

and

:::coffeescript
# 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:

:::coffeescript
# This is 'firstSource.ldpl'
include "includedFile.ldpl"
procedure:
    call someSubprocedure

When you run the code above, it will print

:::text
Hi there!

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.

The include statement can only be used before the data section.

C++ Extensions

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: the flag and extension statements.

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 flag statement.

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:

:::coffeescript
flag "-lSDL"
flag "-fpermissive" # you can pass as many flags as you want
data:
    #...
procedure:
    #...

Often, different operating systems require different flags. In those cases, you can restrict the flag statement to a particular OS:

:::coffeescript
flag "-O3"
flag linux "-lncursesw"
flag macos "-lncurses"
flag macos "-D_XOPEN_SOURCE_EXTENDED" # multiple flags per OS are permitted
data:
    #...
procedure:
    #...

!!! tip LDPL officially supports the following operating systems:

- Linux
- MacOS
- Android

And includes experimental support for these fine systems:

- BSD
- Emscripten

The 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:

:::coffeescript
extension "someDirectory/someFile.cpp"
flag "-O3"
data:
    #...
procedure:
    #...

The extension statement can only be used before the data section.