Mlang
The Mlang compiler has a traditionnal architecture consisting of various intermediate representations going from the source code to the target backend.
Frontend
First, the source code is parsed according to the Menhir grammar specified in M_frontend.Mparser. The grammar is not exactly LR(1) so we rely on M_frontend.Parse_utils to backtrack, especially on symbol parsing. The target intermediate representation is M_frontend.Mast, which is very close to the concrete syntax and can be printed using M_frontend.Format_mast. The frontend also handles ast expansion with M_frontend.Expander and validation with M_frontend.Validator.
M_frontend.ExpanderM_frontend.MastM_frontend.MlexerM_frontend.MparserM_frontend.Parse_utilsM_frontend.Validator
Intermediate Representation
The M language has a lot of weird syntactic sugars and constructs linked to its usage inside multiple DGFiP applications. M_frontend.Mast_to_mir extracts from the AST of M_frontend.Mast the computational core corresponding to a DGFiP application into the M Variable Graph (M_ir.Mir), which consists basically of a flat map of all the definitions of the variables used in the application. The type system of M is very primitive, and basically all programs typecheck ; however M_frontend.Validator provides a top-down typechecking algorithm to split simple variables from tables.
Testing
Mlang comes with a testing framework for M programs that is based on the test format used by the DGFiP. The test files are parsed with Irj_utils.Irj_file. Then, single or batch testing can be performed using Irj_utils.Test_interpreter.
Irj_utils.Irj_astIrj_utils.Irj_fileIrj_utils.Irj_lexerIrj_utils.Irj_parserIrj_utils.ParserMessagesIrj_utils.Test_interpreter
Compiling
M/M++ programs can be compiled to other programming languages using several backends that take BIR and produce source code files in their respective languages.
Backend_compilers.Bir_to_dgfip_cBackend_compilers.DecoupledExprBackend_compilers.Dgfip_compir_filesBackend_compilers.Dgfip_gen_filesBackend_compilers.Dgfip_varidBackend_compilers.Prelude