|
<< Click to Display Table of Contents >> Navigation: 2. Components > 1. PreProcessor & EXE-Compiler > 1. PreProcessor |
MiniRobotLanguage (MRL)
1.7 #SCSA / #CASE / #CSEA / #ENSA
Preprocessor Multiple Case Conditions
Intention
This command offers a multiple choice option for the preprocessor.
For example, if you want to make several versions of a program with the same source code, you can now specify a version number with the preprocessor variable and depending on the version number, the version number is then selected here via Case and the corresponding code parts are then compiled.
#Case can also contain a formula in brackets instead of just a number and in this way evaluate several adjacent version numbers.
#Case can also be followed by multiple elements separated by a ",". Formulas must be in ( ...).
#CASE 1,3,5,(5*$AAA)
There is an Order of processing inside the Pre-Processor, the following Commands are processed sequentially:
1. #INC:
2. #LIB:
2. #ONCE / #OEND / #OREM
4. #VARD
5. #IFVA / #ELSA / # EIFA and #IFVL
6. #SCSA / #CASE / #CSEA / #ENSA
7. Macros etc.
8. Collecting Labels
This is important, because of this you can use the Preprocessor to remove Macro-Lines and Labels from the Code.
You can not use t to remove #INC: or #LIB: from the Code as its processed before, with highest Priority.
ts even processed before #ONCE: therefore #ONCE will not protect from these directives.
Generally the Priority of #ONCE ... #OEND is the highest.
Anything that is in there will be removed from the Code if the Condition s "Duplicate".
Of course the Directives themselves will also be removed from the final Code as well before Execution.
Generally Directives are processed and removed in one step.
In the next step the Compiler defines numerical Variables in Model-Space 255.
These Variables are available from that Moment and can be used inside #IFVA, #IFVL #SCSA, and wth #CASE .
For example like this:
#VARD $$VER=3
#IFVL $$VER>1
Here is a Real-Life Sample from the "Twitter-Button Bar" from Sample-Code Folder.
Using this System, we can remove Lines with Macros from the Code before the Script starts running.
#VARD $$VER=1
%SetText Letztes Diktat|Zuletzt diktierten Text wiederherstellen und einfügen.
#IFVL $$VER>1
%SetText UnDo|Letzte Textänderung im Arbeitsbereich rückgängig machen.
'-------
%SetText Schiller//Goethe|Zwischenablage-Text in Schillers oder Goethe's poetischem Stil neu interpretieren.
#IFVA $$VER>1
%SetText E. Roth//Sam Hawkins|Zwischenablage-Text im humorvollen Stil von Eugen Roth oder SAm Hawkins neu dichten.
%SetText W. Busch//Morgenstern|Zwischenablage-Text in Wilhelm Buschs oder Christian Morgenstern's satirischem Versmaß umwandeln.
%SetText Dichter//Erhard|Zwischenablage-Text im Stil eines wählbaren Dichters oder RMB: Heinz Erhardt's Stil neu interpretieren.
#EIFA
Important Implications:
This will also prevent the use for the "higher Constructs" (1.-6.) Inside Macros, because at the Time of Macro-Expansion, they simply do not exist anymore.
You can generally nest these Construction. Again there is a Priority that the most outer Construct will remove anything inside if the Condition is not "True".
It does not matter f a "inner Condition" is true or not, f the outer Condition is False.
' This the case where its removed from the Code
#VARD $$VER=3
#IFVA $$VER>3
#IFVA $$VER>1
.. Will be removed
#EIFA
#EIFA
' This the case where ts not removed
#VARD $$VER=3
#IFVA $$VER>2
#IFVA $$VER>1
.. Will not be removed
#EIFA
#EIFA
You also need to understand that the #SCSA are generally processed after the #IFVA and therefore have a general Priority.
However that seems to not be any problem, as it does not Matter when a Construct is removed. In cases like below, first the #IFVA are processed and in the next Pass the #SCSA are processed.
The result is the same.
#VARD $$VER=3
#SCSA $$VER
#CASE 1
#IFVA=3
... will be removed from the #SCSA
#EIFA
#CASE 2
#CSEA
#ENSA
Syntax
#SCSA P1
#CASE P1[,Px]
#CSEA
#ENSA
Parameter Explanation
P1 - Value or Pre-Processor-Variable.
Can also be a numerical Value or a calculation in (). Can also be another numerical Variable that was defined before by the Preprocessor Command #VARD.
Anything that does not evaluate to a Integer (32-bit) will be treated a "0".
Any value that is not "0" will evaluate to "True" and make the condition to be "True".
Can contain multiple Elements separated by comma, if any of these elements evaluates to "True" the condition is true.
Example
'***********************************
' #SCSA.-Sample
'***********************************
' These Vars are set at Preprocessiing time in MODULE Nr.255
#VARD $$AAA=1
#VARD $$AAB=4
#SCSA $$AAA
#CASE ($$AAB/4),4
DBP.1 o.4
#CASE 2
DBP.2
#CASE 3
DBP.3
#CSEA
DBP.ElseA
#ENSA
DMP.Speed
MBX.!
ENR.
Remarks
-
Limitations:
-
See also:
•