Transformations for Antlr grammars

At this point, I am working on the code for refactoring Antlr grammars in Antlrvsix. While I plan to use Piggy to implement these refactorings, I will first implement them in C# code so I can get a clear picture of what to do with Piggy, make any changes, then rewrite the refactorings using Piggy templates.

Here is a preliminary list of some transformations I plan to write:

  • Convert string literals in parser with lexer token types.
  • Remove useless productions.
  • Move start symbol to the top of parser grammar.
  • Order parser rules (a) alphabetically, (b) DFS traversal, or (c) BFS traversal.
  • Separate/combine lexer and parser grammars.
  • Convert parser rules to fragment lexer rules and vice versa.
  • Move lexer fragment rules to top/bottom.
  • Order modes in alphabetic order.
  • Remove left recursion.

The first three transformations have already been added to Antlrvsix. Here are some clips on how they work.

Additionally, there are a number of papers to check out.

–Ken

Leave a comment

Your email address will not be published.