There are different possible notations for languages: textual and graphical are the two larger families.
We can define graphical notations for formal languages. For example we can define a graphical notation to define state machines.
A Domain Specific Language for state machines can be defined using JetBrains MPS. However the user would have to edit the state machine inside MPS.
I wonder if we could instead specify a state machine just by sketching something on a whiteboard. Consider this example:
We have a start state (the white circle on top) which leads us to the state A without needing any event. Then from state A we can go to state B when an event of type b occurs. Or we can go to state C if an event of type a occurs. From C we need a state of type c to move to D.
Note that I did not represent the direction of transitions, we could assume that they always lead from the higher state to the lower.
I think that at this point we should just make a picture to this sketch and obtain a program which would permit to run this state machine.
To do that we should recognize the different shape, the text present and assign everything to a corresponding concept in our DSL.
The first step would be to recognize rectangles. I guess there are already libraries to do that. I tried OpenCV but I really do not like the way C++ dependencies are handled. I started playing with BoofCV instead, which is written in Java. I first used functions to recognize segments and I got something like this:
Then I wrote some functions to merge segments which have endpoints very close and similar slope, to reduce the number of segments. That did not work particularly well.
I realized I should probably use some pre-processing: first a Gaussian blur and then calculate the derivatives over the X and Y axis. I got something like this. The colors depends on the values present in the derivates X and Y images. I should use those values to recognize horizontal and vertical lines with common endpoints and so get rectangles.
This is not as easy as I hoped but I would love to spend more time on it in the future.
Still, people will need some ability to formalize their thoughts but we can definitely remove some of the incidental barriers due to languages, notations and tools.
Related articles across the web
Download the guide with 68 resources on Creating Programming Languages
Receive the guide to your inbox to read it on all your devices when you have time