MPL Documentation

Basic Syntax

Revised: October 2022

Programming, much like art, has significant flexibility for coders: there is no "one right way" to enter your code into the engine. You pass a filename to the engine via the command line or a configuration file. The MP parser is capable of processing even obfuscated pascal source, as the grammar specifies each token is separated by a form of white space or operator. As an example, the following both represent acceptable (valid) syntax under MP:

   If A>1 then Writeln('Greater');
   If (A>1)
Visually they are clearly different.  However, consider the following syntactic rule:

Any consecutive letters are first considered an IDENTIFIER until tested against the grammar as a possible keyword or reserved word.

Thus any form of separator (space, punctuation which is usually an operator, or end of line) can be placed anywhere that will not break the flow of logic. Meaning, you could not do, for example, the following - MP does its best to decipher (parse) the code, but there are limits to extrapolation (guessing!):
If A>
Blocks of Code
All code in Pascal dialects are usually grouped between a Begin and an End; just like 'C', C#, JavaScript, etc. use { and }, Pascal was designed to convey the logic is spoken out loud. That is where "Begin" is much shorter than "Open Brace", and "End" is shorter than "Closed Brace". I point this out in long/verbal form, as for many years the argument has been based upon typed characters.

Object Oriented Pascal

Personally I enjoy the evolution of the Modern Pascal OOP programming style.

   MyObjDefinition = Class
         Procedure Init; {more like Turbo Pascal instead of Delphi}
         Procedure Free;
In Modern Pascal, your Class can be a descendent of another, like Class(TComponent), and Modern Pascal does not have the reserved words Constructor nor Destructor. Again, Modern Pascal's primary focus is speed, and reducing the Reserved Words tree during parsing by just 2 commands does impact the performance on a couple million lines of code.
Another difference is Modern Pascal uses self instantiation, to achieve this, the developer must implement the VMT (Virtual Memory Tree) of each class in the MyObjDefinition.Init definition, like so:
Procedure MyObjDefinition.Free;

Procedure MyObjDefinition.Init;
   // Build the RTTI by hand:
   with Self do begin
      TMethod(@Free):=[@MyObjDefinition.Free,@Self]; // Links the FREE method to this class!
Now we have informed the parser how to define the VMT/RTTI of MyObjDefinition. To use it becomes just as simple:

   MOD.Init; {Slick!}
//   Now you could call methods of MOD here, and when you are finished with MOD:
So it requires a little extra typing that other compilers and IDEs inject under the hood during compile time. We did not elect to follow the practice of the compiler making assumptions as we have had scenarios where we needed to control everything at a granular level on some of our multi-gigabyte projects. Now, you the developer have complete control over the VMT/RTTI layer without having a masters degree in compiler development.