The PPL preprocessor converts scr-code to intermediate ppl-representation for immeadiate execution.
Format of statement for preprocessor is no different from normal:
operator <body><end symbol>
For example: var x = value;
Here: operator: var
body: x = 0
end symbol: ;
The set operator is a special case, this operator is used much more often than others, and in many programming languages it is implied but not written. Early versions of the PPL language required the mandatory inclusion of the set operator in the program code, its absence caused errors, so I decided to get rid of the set, that is, instead of
set x = 0;
to write
x = 0;
This process is carried out as follows:
The PPL preprocessor scans the code from left to right to “=” and inserts operators set or setkvp (set key value pair) in the appropriate places according to the following rules:
Symbol “=” appears in the following 2 groups of statements:
- Conditional expressions:
==, <=, >=, !=
- PPL operators:
set, setkvp, array, sinit, ssetrow, sset,var,const, realloc.
Format of these operators is given below:
set name = value;
setkvp name = key,value;
array name[length] = init_value
array name[] = { elem1,elem2,elemN…};
sinit name = init_value;
ssetrow name [ind1,ind2,indN…] = {elem1,elem2,elemN…};
sset name = init_value;
var name = value;
const name = value;
realloc array_name[ new_length] = init_value;
When symbol "= " is found, it checks whether it is an element of the first group, if yes, the search continues.
If not, it scans from right to left to the first end symbol (or to the beginning of the code) and this position is considered the beginning of the statement.
In this case, end symbol is a end symbol of both a simple sentence and a block one and has the following meanings: ; space tab { } ).
Samples of block sentences:
function foo()
{
x = 0;
}
for(I,0,5) x = 0;
for(I,0,5) { x = 0;}
If the found statement does not contain operators
"array", "sinit", "ssetrow", "sset" "var", "const", "realloc",
then the body of the sentence is checked and, in accordance with the format, the operator set or setkvp is inserted at the beginning of it.
It should be added that during the scanning process, comments are skipped, as well as fragments of text enclosed in quotes.
The latest PPL version v.2.0.2 (Tutorial, Programs, Samples) is available here: GitHub - okogosov/PPL: Parenthesis Programming Language (PPL)