The first high-level programming language Plankalkül (Plan Calculus) from Konrad Zuse was developed between 1942 and 1945. Since this time, a lot of languages have been developed and discarded. But how is a language defined? What is a domain specific or visual language? And have all languages equal definition parts? What is different if we use Xtext? Let’s take a look at several definitions and bridge the gap to modern language engineering with Xtext.
Mandatory parts for every language are syntax and semantic. The programmer has to know which kind of programming constructs the language contains, which kind of behavior can be expressed and how to construct correct sentences with that language. We also need a parser to transform written programs into another representation, of course but let’s refrain from talking about the issue of compiler or interpreter for languages for now and save this topic for a next chapter.
In short, we need a syntax and semantic definition. Usually we use context free grammars to define a syntactic structure and with regular expressions we define the literal terminal symbols. With this kind of definition, a simple parser can be generated by parser generator tools. The programmer writes a program in a given language by using a text editor and then translates it for further use.
Language Engineering: textual, visual, general, domain specific
There is no difference in developing a general-purpose language or a domain specific language. Both can be more or less complicated and have different amounts of constructs. Apart from an assembler language, every language describes an abstraction to the target machine if requested. Visual languages contain also syntax and semantics.
Textual languages are a subset of visual languages. The only difference is that the symbol presentation is not textual. This requires a structural editor for representation of the symbols and mechanisms to translate the visual representation to another maybe textual representation. Since they are simpler and easier to use most people favor visual languages. This is also due to tool support and IDE.
So why can’t we create powerful IDEs for textual languages with some comfort functions? How about we use a domain specific language with tool support to make things easier? Great idea but there are many solutions already available and one of them is actually Xtext.
Language Engineering with Xtext
Xtext allows developing powerful domain specific languages with full tool chain support. With Xtext we can develop the language itself and different support functions like highlighting, auto completion functions etc. Let’s take a look at what kind of features Xtext brings along at the moment.
Language engineering with Xtext can be divided in three parts: language definition, IDE and usage. Language definition will be done with Xtext through definition of regular expressions for the literal symbols and context free grammar as a set of grammar rules. This way, the defined language also defines the IDE with primitive rules validations.
Language engineers get feedback about structural correctness of the designed grammar and the programmer or user of this particular language gets feedback about syntactical correctness of programs in the given language. Even the simplest specifications deliver added benefit in Xtext.
Creating an Xtext project also generates several further plugins for the IDE, JUnit tests, UI tests etc. To assist developers, support through UI can contain quick fixes, highlighting and content assistant. Other customizations of the IDE are possible, such as through modelling of the outline view or using of labels.
As a last component for using a language, a code generator can be implemented with Xtend. In addition, Eclipse allows integrating extended build mechanism and other comfortable features.
Xtext version 1.0 was released in 2010. Today we work with version 2.11. For everyone starting now, the book "Implementing Domain-Specific Languages with Xtext and Xtend" from Lorenzo Bettini is an absolute must-read. Other sources are eclipse.org or StackOverflow.
Our compiled "1001 tips and tricks for Xtext" represents a handy FAQ for everyone working with Xtext. This compilation will be continuously updated with new challenges and questions from related forums like stackoverflow.com or eclipse.org/forums. Download our first release by clicking the button below.