6

This is a rather technical question about the compilation process of ABAP code.

I know that there are ABAP parser and scanner classes that actually call C kernel functions to do the real work. Then there is code completion functionality with a transaction that returns and prints the AST (abstract source tree) of a program as ABAP list or XML.

Now my question is: would it be possible to 'skip' the ABAP source code and directly produce such an AST by other means than writing and then executing an ABAP program in SE80 or so, and give it to some function that compiles and executes it as if it had been written in and parsed from ABAP code?

That is, can I skip scanning and parsing of sources and directly give an AST to the compiler? If so, in what format? ABAP lists look more a printing format, not like e.g. Lisp lists surrounded by parentheses.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Thorsten
  • 3,451
  • 3
  • 20
  • 25
  • 1
    Why would you want to do that? It sounds unnecessarily complicated, besides being unsupported, which is always an issue with mission-critical systems... – vwegert Jan 01 '16 at 22:03
  • 2
    The ASTs of a few ABAP programs I tested looked really straight forward (especially in ABAP list form), it shouldn't be too difficult to create them manually. Why? Not sure really, but it looks like an interesting idea to me. It's the HOW I'm interested in. What ABAP (Kernel) program is fed with this AST for compilation? What kind of datatype is this AST, how can one create one? – Thorsten Jan 01 '16 at 22:36
  • 1
    Since the compiler works on source text, what you could do is prettyprint your AST to produce source text. See my SO answer on how to build a prettyprinter: http://stackoverflow.com/a/5834775/120163 – Ira Baxter Feb 10 '16 at 15:00
  • @Ira Thanks, great post to be discovered when following the link! – Thorsten Feb 11 '16 at 17:19

1 Answers1

4

Unfortunately, the ABAP Compiler does not use ASTs to generate the VM code. The ABAP compiler works sequentially and translates statement per statement (i.e. everything that is between two ".") into one or more virtual machine opcodes.

If you are curious, you could take a look at transaction SYNT which shows the compiler output. You could also take a look at report RSLOAD00 which shows the ABAP VM code that has been generated for a program.

ASTs have only been built on top to allow for code completion or high-level analyses.

If you want to invoke the ABAP compiler, you will need to generate textual ABAP source code.

  • Ok. thanks, too bad actually - it would be so much easier to produce the AST than the textual ABAP source. And in my experience generating program code that stands for itself always carries the temptation to debug and edit the generated code instead of the generator code. – Thorsten Feb 11 '16 at 17:17