I would like to generate TTCN-3 code programmatically and preferably in Java. Unfortunately, this task is far from trivial.
I already tried to "abstract" TTCN-3 partially with POJOs and use the StringBuilder to generate the TTCN-3 code. IMHO this approach was quite simple in the beginning but appeared to be not feasible for more complex use cases.
So I moved on to ANTLR respectively Xtext, which seems to be the right way to go. Xtext utilizes ANTLR and builds a Lexer, Parser and Class Model for the AST and is even able to check the syntax and serialize the AST, exactly what I was looking for.
But describing the TTCN-3 grammar correctly in Xtext is even further from trivial. At least for me, as I don't have any experience with context-free grammars.
The next idea was to utilize Titan's code base for this task. Notably xsdconvert and titan.EclipsePlug-ins codegenerator seem to be promising. But I couldn't figure out whether the codegenerator is also able to produce TTCN-3 code or how I could utilize xsdconvert for this purpose.
Does anyone have any further ideas or suggestions?
First of all you will need to decide on the strength of the task at hand.
If you are "just" building TTCN-3 code, the simple appending strings approach might be ok.
If you wish to convert some data structure or FSM, you could still find a string appending approach useful ... although you will most probably use a visitor or some other pattern to traverse the data structures in the right order.
But if you have something way more complex at your hand, like translating Java to TTCN-3 ... than you will need to write a compiler (like Java/gcc/titan/etc..) which could mean several years of work even for people how have extensive experience in compiler construction.
To help with the problem at hand there are 2 things I don't understand based on your description.
If I understand correctly you wish to output TTCN-3 code from some other input.
In this case you do not need a lexer/parser/AST/etc.. for TTCN-3 since that is not the input you will parse.
For example the xsd converter parses XSD file to output TTCN-3 file, and both the compiler parses TTCN-3 files to output C++ files.
In both cases generating the output is basically just string concatenation, after all data is already processed.
Could you please give some information on you input?
I don't see if you have some data structure to process, or a program in some programming language as input.
Actually, I don't really need a compiler/lexer because I will only need to generate TTCN-3 code. During my investigation on that topic, I stumbled over Xtext, which claims to make language engineering easy and was curious about that. However, I underestimated the complexity of TTCN-3.
My current project is quite similar to xsd2ttcn and Elemer's example, but the target will be something like swagger2ttcn. Accordingly, my inputs are Swagger files which I want to translate to TTCN-3 Template Definitions.
Thank you for your advice. I will proceed with appending string approach for now.