TRUDUtilsD365
TRUDUtilsD365 copied to clipboard
Proposal: Create a simple interpreter for X++ language
Objective
Create a simple interpreter for the X++ language to quickly test specific functions without compiling the entire application.
Background
To test a functionality in X++ currently, such as understanding how a particular function operates, one must compile the entire application, which can be time-consuming. I aim to introduce an interpreter to reduce this overhead and offer a swift testing platform.
Example
Input:
LedgerJournalCheckPost ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable::find("AAA"), NoYes::Yes);
ledgerJournalCheckPost.runOperation();
Expected Output:
- The syntax analyser generates and returns the syntax tree for this input.
- The interpreter instantiates the
ledgerJournalCheckPost
object and runs the journal posting.
Implementation Breakdown
- Syntax Analysis: We need a syntax analyser before building the interpreter. This component should accept the X++ code as input and produce a syntax tree. I need some help with this. It can be written in either C# or X++.
- Interpretation: Upon having the syntax tree, we can construct the interpreter to execute the actions. I'll take care of this aspect.
Plan
-
Research:
- Explore existing code analysers for C#. Useful resources:
- Coco/R appears promising from preliminary observations: Coco/R
- antlr looks good http://lab.antlr.org/
-
Grammar Conversion:
- Transition the X++ grammar to an appropriate format. Reference: X++ Grammar
- Optionally you may simplify the grammar to cover only select functionalities: object creation, method execution with parameters, and "while select" actions.
-
Develop the Syntax Analyser:
- Create a tool that ingests X++ code and delivers a detailed syntax tree.
-
Construct the Interpreter:
- Using the output from the syntax tree, craft the interpreter to carry out the relevant X++ tasks. I'll oversee this phase.
Ideal Collaborator
For Computer Science students focusing on "Compiler Generation", this project could serve as an exemplary hands-on assignment. Your proficiency in compiler design, especially syntax analysis, would be invaluable.
Simple grammar for http://lab.antlr.org/ test case: SalesTotals salesTotalsVar; SalesTable salesTable; SalesLine salesLineVar;
TaxAmountCur salesAmt;
Tax tax;
salesTable = SalesTable::find("SO00094903");
salesLineVar = SalesLine::find(salesTable.SalesId);
salesTotals = SalesTotals::construct(salesTable, SalesUpdate::All);
tax = Tax::construct(NoYes::No);
salesAmt = salesTotals.totalBalance();
` grammar Ledger;
// Parser Rules parse : statement+ EOF ;
statement
: declaration ';'
| methodCall ';'
| staticMethodCall ';'
| assigmentCall ';'
;
assigmentCall : IDENTIFIER '=' staticMethodCall | IDENTIFIER '=' methodCall ;
declaration : type IDENTIFIER '=' staticMethodCall | type IDENTIFIER ;
methodCall : IDENTIFIER '.' IDENTIFIER '(' argumentList? ')' ;
staticMethodCall : IDENTIFIER '::' IDENTIFIER '(' argumentList? ')' ;
argumentList : argument (',' argument)* ;
argument : staticMethodCall | enumValue | STRING | tableField | IDENTIFIER ;
tableField : IDENTIFIER '.' IDENTIFIER ;
enumValue : IDENTIFIER '::' IDENTIFIER ;
type : IDENTIFIER ;
// Lexer Rules DOT : '.' ;
COLONCOLON : '::' ;
STRING : '"' (ESC | ~["\])* '"' ;
fragment ESC : '\' (["\/bfnrt] | UNICODE) ;
fragment UNICODE : 'u' HEX HEX HEX HEX ;
fragment HEX : [0-9a-fA-F] ;
WS : [ \t\r\n]+ -> skip ;
IDENTIFIER : [a-zA-Z_] [a-zA-Z_0-9]* ;
`