DEV Community

Dragan
Dragan

Posted on • Updated on

Visual AKDL Editor

It all begun with my intention to create a new programming langage called CLApp (I’ve described in my first post). At the beginning (I’m from the old school), I started with the writing of my own lexer, my own parser and code generator (in C and, later in java), as a colleague of mine suggested to me to use ANTLR. This should have prevented me from writing that much. Another advantage: if I have to modify something in my language definition, I wouldn’t need to search in the different parts of my code where to adapt it to the new features; ANTLR would re-generate all the stuff for me.
So I tried that, but… my syntax didn’t fit to all ANTLR expectations; I was obliged to adapt my definitions to the tool. And at some time, it was too much and thus I decided to create my own tool that should do the same job as ANTLR but in a way I desire. And AKDL was born.
AKDL means Another Keyword Definition Language. Its’ main features are listed below:

  1. It generates java code
  2. The generated code, parser and runtime, appears in classes representing the defined keywords; it is stored within packages specified by the syntax designer. In other words, you can structure the whole code that AKDL generates for you.
  3. Having 1 parsing class per keyword allows you to have as many entry points as keywords. That means you are able to parse snippets and are not obliged to have a complete source of your language to get its corresponding runtime. You can thus use those snippets to deploy them and let them run within an already existing application (as example of use).

Traditionally, to define a keyword, the EBNF (Extended Bachus-Naur Form) notation is used. In this notation, as you probably know, you have :

  1. Brackets « [] » for the option ; for example, [a b c] means group (a b c) is optional
  2. Braces « {} » for the quantification ; for example, {a b c} means group (a b c) appears an undefined number n of times (n can be 0)
  3. The vertical bar symbol « | » is used for the alternative ; for example, a | b | c means only one element out of the group (a b c) will be selected

It appeared relatively soon that this good old notation won’t fullfill my expectations. The 1st stuff I’ve seen at glance was that point 3 was absolutely not consistent with the 2 others. Another thing I could not accept was that brackets as well as braces had 2 rules at the same time: they were used to group elements AND to apply an operation on them. Moreover, if a group is made of 1 element, you have something like [a] or {a}, which is not a big deal but also not really pretty.
In my case the problem was I needed to add some more operators beside the 3 mentioned above and this notation didn’t really allow me to do it. That’s why I decided to, first, simplify and, then, enhance the EBNF.
The simplification leads to this result:

  1. [a b c] is changed to ^(a b c) as well as, [a] is changed to ^a
  2. {a b c} is changed to *(a b c) as well as, {a} is changed to *a
  3. a | b | c is changed to +(a b c)

After having done that, I was able to simply add some new operators. The one I like very much is “in any order you like” and the used symbol for that is « & ».
Thus, &(a b c) means: (a b c) | (a c b) | (b a c) | (b c a) | (c a b) | (c b a)
You can also combine all that. For example:
&(^a *b c) to say a is optional, b appears a certain number of times, c exactly once and the whole in any order you like. (We have concrete cases in java with modifiers like synchronized, public, static …)
I called this new notation seeBNF (simplified and enhanced EBNF). It allows you to simply define a language in a tree form starting from a root which is the initial symbol. That’s exactly the way you can create your syntax using the Visual AKDL Editor.
Now you know enough about AKDL, I propose you discover how it concretely works through the following tutorials:

1st tutorial
2nd tutorial
3rd tutorial

You can also download the whole stuff and test by yourself (it’s a free open source):

AKDL
Visual AKDL Editor

Feel free to give me your feedback. Thanks.

Top comments (0)