TRUDUtilsD365 icon indicating copy to clipboard operation
TRUDUtilsD365 copied to clipboard

Proposal: Create a simple interpreter for X++ language

Open TrudAX opened this issue 10 months ago • 1 comments

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:

  1. The syntax analyser generates and returns the syntax tree for this input.
  2. The interpreter instantiates the ledgerJournalCheckPost object and runs the journal posting.

Implementation Breakdown

  1. 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++.
  2. Interpretation: Upon having the syntax tree, we can construct the interpreter to execute the actions. I'll take care of this aspect.

Plan

  1. Research:

  2. 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.
  3. Develop the Syntax Analyser:

    • Create a tool that ingests X++ code and delivers a detailed syntax tree.
  4. 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.

TrudAX avatar Sep 09 '23 02:09 TrudAX

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]* ;

`

TrudAX avatar Nov 04 '23 02:11 TrudAX