Defining the syntax of extensible languages

The interest in Domain-Specific Languages (DSLs) has been increasing as a way of improving the productivity and read-ability of software. Some modern extensible languages offer facilities for building modular specifications for extensions, so they may be considered an interesting option for implementing domain specific languages. But there are at least two disadvantages that currently affect most extensible languages. First, their syntax is usually defined informally, because there is a lack of formal tools for the definition of extensible languages. Second, extensible languages are usually implemented in an ad-hoc and inefficient way. In this paper, we show how the syntax of extensible languages like Fortress and SugarJ can be formally defined using a novel model designated Adaptable Parsing Expression Grammars (APEG). The formal definitions of the languages help clarifying many aspects of their syntax. We also use an interpreter of the APEG model to parse programs of the languages, showing that the model can be used in practice to implement parsers for extensible languages.