IX: IXp - A Simple Macro Processor for Python (182.html)

Keywords

ICH180R2 "IXp Macro Processor" IXp Macro Processor Python html entity "&entityName+" Linux syntax parse DC .py _py.ix _pkg.ix "source code" source code parameter "initial value" ICH180 Raspberry Pi "Raspberry Pi" alphanumeric a-z A-Z 0-9 doubleQuote "double quotes" cacheIX buIX "IX Cache" "entity name" entityName concatenation

/KeywordsEnd

(To enlarge .....Click it)
thumb: IXimage.jpg
IX or DC (IX by DC) or "|><"


This software is a part of the IX family of software.

Introduction

WARNING: IXp has not yet been fully coded.

IXp is a simple macro processor to be used for Python programming. It has only three processes that it performs:
-character string replacement
-multiple line replacement
-run the result

This early version of IXc uses entityNames that end in "+". In IXc, the entityNames will end in "|".

IXp reads a specified input file that contains code that greatly resembles Python code. The difference is that somewhere in the code there can be a character string (called an entity) that will be replaced by a new different character string (called the entity value). The user must also specify the entity and the value to be assigned to the entity. Zero or more entities can be replaced by IXp. The new entity values must not contain a Line Feed (the Return key). This means that the substitution (i.e. character string replacement) will not change the line count of the file. A different process called "multiple line replacement" can be used to replace whole lines. Whether or not the input file is changed, a new file (called the output file) will be written into the current folder. Then IXp will send a command to the Terminal window to cause the output file to be run in Python3.

An example of a simple input command line for IXp is shown below:
IXp v0a:
>|
-python3 progA_py.ix?count=3
When reading the above command line, one might say "for" or "with" instead of "?" to convey the correct meaning.

An Input File (a Macro) For IXp

# program progA_py.ix
# invoke this macro file by starting IXp and inputting:
#  >| -python3 progA_py.ix?count=3
for i in range(&count+):
    #process the value i and print out the result

    valueOut=i+.1
    print("line",valueOut)

#for end
The above file (called a macro file) will be processed by IXp. IXp will search the input file (the macro file) for all occurences of "&count+" and replace each of them with the string "3". Then IXp will write out the new file into the current folder, giving it a new name which will be "progA.py". The program name "progA" is derived as follows: it is the character string before the "_" in the input file name. The "py" is the character string between the "_" and the ".".

Then IXp will submit the following command into the Raspberry Pi's Terminal window:

>$ python3 progA.py
This will result in running the output file through Python3. The resulting program will print out the following 3 lines:

line 1.1
line 2.1
line 3.1
The above example demonstrates the first and last of the 3 processes that IXp can perform. More than one entity can be defined in the command line and each entity can be replaced in more than one place in the input file. Note that during "character string replacement" the replacement text string must not contain an entity name.

Multiple Line Replacement

When multiple lines are to be substituted for an entity, it is done by replacing an entity by a complete macro file. This must not result in a never-ending loop of replacements. The following example will be used to include a second macro file (shown below):

    # this macro file is named processThis.ix and can include any Python statements
    # this macro processes &eachValue+ and prints out a line
    # note that in this Python example &eachValue+ must be an integer (for the print statement to work correctly)

    valueOut=&eachValue+ +.1
    print("line",valueOut)

    # note that indentation was required in this macro for Python to process the result correctly
An IXp macro file does not need to have any special first or last lines. An IXp macro is usually composed of lines of Python code. The revised first file (to make use of "processThis.ix") is:

# program progA_py.ix
for i in range(&count+):
    # note that the string substituted for "eachValue" must be an integer

    &processThis+?eachValue=i

#for end
It is the responsibility of the programmer to ensure that the code in the macro, when expanded, will result in valid Python statements.

The same command line (as in the first example) is required to run this example:

IXp v0a: >$ python3 progA_py.ix?count=3
For IXp to function correctly, the two macros "processThis.ix" and "progA_py.ix" must be available to the IXp processor. They are indeed available to the IXp processor if they are both in the current folder. Sometimes, after substitution, part of the substituted string might be the wrong variable type. It is up to the programmer to resolve such issues. Note that the macro "processThis.ix" is not mentioned in the command line. It is only mentioned in the macro (code segment) named "progA_py.ix" (which is mentioned in the command line).

Of course, when run, the same results (as in the first example) are printed, as shown below.
line 1.1
line 2.1
line 3.1

The Resulting Program "progA.py"

The resulting program "progA.py" (that was automatically created and run) to produce the above output is shown below:
# program progA_py.ix
for i in range(3):
    # note that the string substituted for eachValue is an integer
    # this macro file is named processThis.ix and can include any Python statements
    # this macro processes &eachValue+ and prints out a line
    # note that in this Python example &eachValue+ must be an integer (for the print statement to work correctly)

    valueOut=i +.1
    print("line",valueOut)

    # note that indentation was required in this macro, for Python to process the result correctly
#for end

Other Information About IXp

IXp is designed to run on the Raspberry Pi. The output file, "progA.py", will be stored and left in the current folder (where the input files were located) which is "/home/pi/". The print statement in this example may not work if Python2 is used with IXp. Three files (the command, the package of ".ix" files and the new python output file) will all be time-stamped and backed up in the /home/pi/buIX/ folder. These backups are kept so that the whole IXp process can be rerun at a later date, if desired.

The two examples above do not illustrate this, but IXp will process and concatenate multiple files if they are listed on the command line one after the other. The resulting output file will be assigned a name derived from parts of the name of the last file on the command line (as explained earlier).

The 8-bit USASCII character set used by IXp can be seen at Web Source 01 below.

Conclusions Re IXp

The IXp macro processor is a very simple program, itself written in Python3. IXp is powerful enough to greatly simplify the development of complex Python programs. The macro facilities in IXp aid greatly in the documentation of the programs it creates. Of course, the IXp macros can be used to define or invoke similar (but different) Python functions. The saving of a backup of each run of IXp fully documents the creation of the resulting Python program. The concatentation of code files performed by IXp also contributes to the power of IXp.

Using this concatenation process, a whole library of Python code (code segments, subroutines and/or functions) can be combined with a main program to produce a final working program. A library of code can be created and maintained in a code package, "_pkg.ix", using the textPack routine described elsewhere in these articles. Multiple ".ix" macros can be packaged together into a single IX package whose name ends in the suffix "_pkg.ix".

The backup of the IXp input (commands, macro files and resulting program) in the IX Cache, uses a large amount of storage space. But today (in 2022), storage space is usually readily available. This IX Cache backup facility (which can be ignored or suppressed) can help the user to identify "bad code" or keep "good code" that was introduced during the development process. See Source 02 for a more thorough explanation of IX packages.

Source 02 describes IX and IXc, which are even more powerful versions of IXp.

Sources

Video Sources

Video Source V182:01: First Look at the Tiny2040 (3:14 min) by Learn Embedded Systems c2021DApr


Web Sources

Web Source S182:01: US ASCII Chart 8-bit at charset.org/charsets/us-ascii on 2022FJun15
Web Source S182:02: IT: IX/IXc - A General Purpose Macro Processor (183.html) by D@CC on 2023HAug30

/SourcesEnd

WebMaster: Ye Old King Cole

Click here to return to Articles by Old King Cole

Date Written : 2022 F Jun 23
Last Updated: 2023 K Nov 23
All rights reserved 2023 by © ICH180RR

Font: Courier New 10
/182.html