AQL ANTLR4-grammar

ANASTASIOU A. a.anastasiou at
Mon Aug 24 04:32:57 EDT 2015

Hello everyone

Please see further below regarding a few first steps towards "converting" Chunlan's .g files in combination with Eiffel's lexer files to ANTLR's syntax. My main motivation for doing this was to produce syntax diagrams for ADL and AQL but very early on I realized that there was no point writing just the EBNF because I could be deriving the ANTLR representation of the grammar and from that be able to produce a parser as well.

This was going well, until I realised that:

1) Certain definitions could be defined once and re-used in multiple places
2) Some definitions looked almost exactly the same but had different names depending where they were applied
3) Some definitions would become obsolete / would not be able to co-exist because of the way ANTLR expresses a grammar
4) Some definitions included conditional parsing with states and they were becoming a bit indecipherable for me
5) Meantime, ADL 2.0 came along

I have specific examples for the above in a document were I kept notes as I was going on which I intend to share. Part of it was also put at an earlier email to Thomas...but this was long time ago by now.

The problem is that right now I am "on the road" (and have been for a few weeks now), writing this just before I go into class at St. Andrews and cannot talk about this to the level of detail I would love to :D

However, the key messages emerging from my experience are these:

A) I would appreciate help from people who wrote the .g and Eiffel YACC files because these are not exactly documented. We need to know how some definitions came to existence and more importantly, if we have two definitions that are almost identical, which one do we keep?

B) !!!We need testing cases!!! for each definition. This became essential as I was going on and had to jump back and forth changing definitions. Of course, when you do that, it has an impact on every definition uses the modified part. My tool of preference was Python. The Python ANTLR target code generation was recently reworked and it works almost exactly as its JAVA counterpart. It could be used to create quick test code through a makefile or something.

C) I found it easier to work bottom-up. So, if we were to quickly get elementary data types / definitions out of the way relatively quickly then the real work can start on parts of the grammar that are not exactly straightforward :)

Repositories at:
A first step for AQL can be found at:

Some progress has also been made towards EBNF for ADL at:

I hope this helps, had a quick look at the MedInfo stuff and it looks really exciting!

All the best
Athanasios Anastasiou

From: openEHR-technical [openehr-technical-bounces at] on behalf of Thomas Beale [thomas.beale at]
Sent: 03 July 2015 11:10
To: For openEHR technical discussions; For openEHR clinical discussions
Subject: Re: openEHR specifications - the future is Asciidoctor + MagicDraw?


excellent suggestion. I haven't even looked at building in syntax diagrams right now, but your timing is perfect - I was contemplating how to put the ADL grammar into the new style spec in a nice way. Currently grammar is generated as an HTML page (as per links on this wiki page<>) which is ok, but the source file is not in a re-usable form (it's a .y file containing Eiffel code - but it would be the same problem with any language like Java or C etc) and the lexer files are also not re-usable or easily publishable.

So we need to solve this in a way that makes the lexer and parser grammar files primary, and then all other files based on them. All of this goes for AQL as well.

Both ADL and AQL grammars can undoubtedly be improved - there is not only one grammar for a language - so making changes for computability doesn't have to break the language definition. I suspect that if we can get some optimal grammars sorted out for Antlr, they will become the 'primary files' for these languages in the ecosystem. Shinji is also after the same thing, and I think has done some work on ADL grammar for Antlr.

So we need to do some work here, and your work looks like a good starting point.

As soon as we have a few more gremlins sorted out in the main toolchain, I'll get myself up to speed on your and Shinji's work here and hopefully we can create a solution which I think then really will make for a powerful models+documentation+programming toolchain.

- thomas

On 03/07/2015 10:56, ANASTASIOU A. wrote:
Hello Thomas

This is looking really good and much more usable and lite than shifting through PDFs.

Just a small suggestion / question.

Will it be possible to have (possibly automatically updated from a single model) syntax diagrams for ADL / AQL?

A first step for AQL can be found at:

Some progress has also been made towards EBNF for ADL at:

Both of these attempts to map the languages were made with the view of creating syntax diagrams which are immensely useful when trying to provide the bigger picture to people with minimal technical background.

The ADL EBNF hit some snags because of various differences in the definitions across different files but in general, it is a straightforward task.

Happy to join forces if something like this is already underway.

More information about the openEHR-technical mailing list