Building a Recursive-Descent Parser for MQL Source Analysis
Summary
This article explains how to build an MQL parser in MQL, using a grammar to recognize source-code structure rather than searching raw text. It introduces terminals, non-terminals, and Backus–Naur-style production rules, then uses a simple assignment language to illustrate how a recursive-descent parser matches input and backtracks when a rule fails. It also discusses scanner and parser roles and the problem of left recursion, which can cause some parser designs to loop without consuming input.
The intended applications include semantic code search, dependency and class analysis, code metrics, formatting, and tools for finding potential errors. The article describes adapting C++ grammar material to MQL and notes that macro expansion remains a difficult compatibility gap: templated macro arguments and calls without semicolons can defeat the described approach. This is a programming-method article, not a trading strategy, and it presents a foundation that would need further work for complex projects.
Key ideas
- Grammar rules let a parser identify code structure that plain text search cannot distinguish.
- A recursive-descent parser checks productions against input and backtracks when alternatives fail.
- Left-recursive rules can cause repeated parsing without progress and need rewriting or loop protection.
- Parsing MQL can support source analysis and tooling, but macro handling limits compatibility with complex code.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.