rascal

Parsing with Antlr g4 in RascalMPL


Is there a way to parse with g4 grammar in Rascal. I have some grammar written in Antlr how can I use it within rascal with having redefine with rascal. Any resource the illustrates this will also be appreciated


Solution

  • It's probably best to just type in the grammar again in Rascal. This should be mostly a one to one mapping, but there are usually simplifications to be done to make the Rascal grammar cleaner. For example the operators of expression sublanguages need only one nonterminal name.

    An automated migration is possible in principle but the guarantees such a transformation can give are limited. It could accidentally introduce parse errors or ambiguity, or remove errors and ambiguity. This is mostly due to the two stage lexing/parsing setup most people work with in ANTLR, while rascal uses a single stage. Therefore it's much better to understand the mapping manually.

    There do exist automated transformations from SDF2 grammars to Rascal, because their semantics is so close.