Parsing M Code by
Having worked in M for many years, I have gradually built up a toolkit of useful utilities to help with development and support of M systems. As a freelancer I work on various sites, and do not necessarily have access to the equipment required to load software on to the clients machine. In this case I just retype my utilities right into the system, along with any enhancements that may be useful at that particular site. One particularly useful bit of code is a parser that scans M source code and breaks it down into individual commands -- this makes it easy to locate calls to labels and other routines, identify operations on particular variables etc... It could also form the basis of a language translator (convert your M to C) or prepasser to enable you to add your own extensions to the M language. A feature that I particularly like is that because of the nature of M's syntax, the parser uses generic code for almost all commands -- only requiring specific code for comment lines ';' and the arguments for the 'F' command. The rest of the code is based on the structure of M being as follows. A line is made up: <optional label><whitespace><optional dots/whitespace><commands> Commands are made up: <command name><colon and optional post conditional><space><arguments><space or end of line> Arguments are: <argument><comma <argument> This code was used to generate an array (CALLTREE) listing all the external calls made by various routines, it may not be perfect but you can do what ever you like to improve it. It was written on ISM running under Unix (but I think it is portable). It can be called as D PROC("^ROUTINE") -- if you save it, you can even make it process itself.
Download and Installation Click here to download this routine. After downloading the archive, unzip it to a subdirectory. Use the Routine Restore command of your M implementation to upload it into the UCI you want to work on. Once loaded, you D ^PROC(<routine>), where <routine> is the name of the program you want to parse. (Try out D ^PROC("^PROC")).
The Source PROC(RTN)ÞS $ZT="NXT" Click here to download this routine.
|