OMeta is a specialized object-oriented programming language for pattern matching, developed by Alessandro Warth and Ian Piumarta in 2007 at the Viewpoints Research Institute. The language is based on parsing expression grammars (PEGs), rather than context-free grammars, with the intent to provide "a natural and convenient way for programmers to implement tokenizers, parsers, visitors, and tree-transformers". OMeta's main goal is to allow a broader audience to use techniques generally available only to language programmers, such as parsing. It is also known for its use in quickly creating prototypes, though programs written in OMeta are noted to be generally less efficient than those written in vanilla (base language) implementations, such as JavaScript. OMeta is noted for its use in creating domain-specific languages, and especially for the maintainability of its implementations (Newcome). OMeta, like other metalanguages, requires a host language; it was originally created as a COLA implementation.
Description OMeta is a metalanguage used to prototype and create domain-specific languages. It was introduced as "an object-oriented language for pattern matching". It uses parsing expression grammars (descriptions of languages "based on recognizing strings instead of generating them") designed "to handle arbitrary kinds of data", such as characters, numbers, strings, atoms, and lists. This increases its versatility, enabling it to work on both structured and unstructured data. The language's main advantage over similar languages is its ability to use the same code for all steps of compiling, e.g., lexing and parsing. OMeta also supports the defining of production rules based on arguments; this can be used to add such rules to OMeta, and the host language that OMeta is running in. Also, these rules can use each other as arguments, creating "higher-order rules", and inheriting each other to gain production rules from existing code. OMeta is capable of using host-language booleans (True/False) while pattern matching; these are referred to as "semantic predicates". OMeta uses generalized pattern-matching to allow programmers to more easily implement and extend phases of compilation with a single tool. OMeta uses grammars to determine the rules in which it operates. The grammars are able to hold an indefinite number of variables due to the use of an __init__ function called when a grammar is created. Grammars can inherit and call each other (using the "foreign production invocation mechanism", enabling grammars to "borrow" each other's input streams), much like classes in full programming languages. OMeta also prioritizes options within a given grammar to remove ambiguity, unlike most metalanguages. After pattern-matching an input to a given grammar, OMeta then assigns each component of the pattern to a variable, which it then feeds into the host language. OMeta uses pattern matching to perform all of the steps of traditional compiling by itself. It first finds patterns in characters to create tokens, then it matches those tokens to its grammar to make syntax trees. Typecheckers then match patterns on the syntax trees to make annotated trees, and visitors do the same to produce other trees. A code generator then pattern-matches the trees to produce the code. In OMeta, it is easy to "traverse through the parse tree since such functionality is natively supported". The metalanguage is noted for its usability in most programming languages, though it is most commonly used in its language of implementation—OMeta/JS, for example, is used in JavaScript. Because it requires a host language, the creators of OMeta refer to it as a "parasitic language".
Development Alessandro Warth and Ian Piumarta developed OMeta at the Viewpoints Research Institute, an organization intended to improve research systems and personal computing, in 2007. They first used a Combined Object Lambda Architecture (COLA), a self-describing language investigated at Viewpoints Research Institute, as OMeta's host language, and later, assisted by Yoshiki Ohshima, ported it to Squeak Smalltalk to verify its usability with multiple host languages. OMeta was also used "to implement a nearly complete subset of…JavaScript" as a case study in its introductory paper.
Use OMeta, like other metalanguages, is used to mainly create domain-specific languages (DSLs); specifically, it is used to quickly prototype DSLs — OMeta's slow running speed and unclear error reports remove much of its function as a full programming language (Heirbaut 73–74). OMeta is useful thanks to its ability to use one syntax for every phase of compiling, allowing it to be used rather than several separate tools to create a compiler. Also, OMeta is valued both for the speed at which it can be used to create DSLs and the significantly lower amount of code it needs to perform such a task in contrast to vanilla implementations, with reports showing around 26% as many lines of functional code as vanilla.
Examples The following is an example of a basic calculator language in C# using OMeta:
It is also possible to create subclasses of languages you have written:
Previously written languages can also be called rather than inherited:
Versions OMeta can theoretically be implemented into any host language, but it is used most often as OMeta/JS, a JavaScript implementation. Warth has stated that patterns in "OMeta/X---where X is some host language" are better left to be influenced by "X" than standardized within OMeta, due to the fact that different host languages recognize different types of objects.
MetaCOLA MetaCOLA was the first implementation of OMeta, used in the language's introductory paper. MetaCOLA implemented OMeta's first test codes, and was one of the three forms (the others being OMeta/Squeak and a nearly-finished OMeta/JS) of the language made prior to its release.
OMeta/Squeak OMeta/Squeak was a port of OMeta used during the initial demonstration of the system. OMeta/Squeak is used "to experiment with alternative syntaxes for the Squeak EToys system" OMeta/Squeak requires square brackets and "pointy brackets" (braces) in rule operations, unlike OMeta/JS, which requires only square brackets. OMeta/Squeak 2, however, features syntax more similar to that of OMeta/JS. Unlike the COLA implementation of OMeta, the Squeak version does not memorize intermediate results (store numbers already used in calculation).
… excerpt ends here. Continue reading the full article.