Discussion of article "MQL Parsing by Means of MQL"

 

New article MQL Parsing by Means of MQL has been published:

The article describes a preprocessor, a scanner, and a parser to be used in parsing the MQL-based source codes. MQL implementation is attached.

Programming is essentially formalizing and automating some processes using general-purpose or special-purpose languages. The MetaTrader trading platform allows applying programming to solving a wide variety of the trader's problems, using embedded MQL language. Normally, the coding process is based on analyzing and processing application data according to the rules specified in source codes. However, a need sometimes arises for analyzing and processing the source codes themselves. Here are some examples.

One of the most consistent and popular tasks is contextual and semantic search in source code base. Surely, you can search for strings in a source code as in a normal text; however, the semantics of the sought for is getting lost. After all, in case of source codes, it is desirable to distinguish among the specifics of using the substring in each specific case. If a programmer wants to find where a specific variable is used, such as "notification," then a simple search by its name can return much more than necessary, where the string occurs in other values, such as a method name or a literal, or in comments.

A more complicated and sought for, as a rule, at larger projects, is the task of identifying code structure, dependencies, and class hierarchy. It is closely connected to meta-programming that allows performing code refactoring/improving and code generation. Recall that MetaEditor provides some opportunities of generating codes, particularly, creating the source codes of Expert Advisors using Wizard or forming a header file by source code. However, the potentials of this technology are much more powerful.

Code structure analysis allows computing various quality metrics and statistics, as well as finding the typical sources of runtime errors that cannot be detected by the compiler. In fact, compiler itself is, of course, the first tool of analyzing a source code and returns warnings of many types; however, checking for all potential errors is not usually built into it — this task is too large, so it is normally assigned to separate programs.

Moreover, parsing source codes is used for styling (formatting) and obfuscation (scrambling).

UML-Diagram of MQL Parsing Classes

Author: Stanislav Korotky

 

Hi, I am a relative newbie here.

Having read the article assumed the RESULT would be a search tool to look up code generated by the wizard.

Downloaded the zip file. Installed the script mql.mq5 compiled it without errors.

Running mql.ex5 produces no result on screen.

I am in learn mode. Want to be able to use the wizard to use code out of the codebase then analyze and modify to get a usable EA.

Any help would be appreciated.

Thanks

 
David_NZ:

Hi, I am a relative newbie here.

Having read the article assumed the RESULT would be a search tool to look up code generated by the wizard.

Downloaded the zip file. Installed the script mql.mq5 compiled it without errors.

Running mql.ex5 produces no result on screen.

I am in learn mode. Want to be able to use the wizard to use code out of the codebase then analyze and modify to get a usable EA.

Any help would be appreciated.

Thanks

This is not "a search tool to look up code generated by the wizard". I wrote the article in Russian, and did not proofread its English translation made by MQ (they do not practice that), but I hope the article contains all details and is clear enough on what the presented scripts can do. Specifically MQL analysis is demonstrated by extraction of class hierarchy and methods from sources. I do not understand which wizard you mean.

You should explain exactly what you did (including some preparations on the system level required to run the script), and what you get. Which result on screen do you expect? The script outputs results in the log.

Since you have the source code, you can debug the script and find out what happens line by line.

 

Hi Stan,

Thanks for taking the time to reply.

Was not aware of where the Print commands in a script writes to a log file.

Yes there is a log file produced when I run the script.

I am constantly frustrated in looking at code created by (Wizard in MetaEditor new doc)

Calls to functions not in the opened file #includes then down more #include levels.

Was hoping your script would have a search box and then tell me which *.mqh file the function was hidden in.

As this script is not a search facility I will not take up more of your time.

Thanks

 
David_NZ:

Hi Stan,

Thanks for taking the time to reply.

Was not aware of where the Print commands in a script writes to a log file.

Yes there is a log file produced when I run the script.

I am constantly frustrated in looking at code created by (Wizard in MetaEditor new doc)

Calls to functions not in the opened file #includes then down more #include levels.

Was hoping your script would have a search box and then tell me which *.mqh file the function was hidden in.

As this script is not a search facility I will not take up more of your time.

Thanks

The script does parse the source code and follow all nested includes, but it does not provide a ready-made solution to show you which header file contains specific function - for this purpose the script should be customized for your needs.

You still did not make clear what is your requirement/use-case.

If you have just cretaed a new program by MQL wizard and want to drill down all its sources including the dependencies (header files), then you can easily do it right from MetaEditor: right click any identifier by mouse to open the context menu, then click "Go to definition" (Alt+G) - this will open required file and show you where the function or variable comes from.

 

Hi Stan, Your last paragraph was the solution I needed.

Thanks.

Reason: