Grammax

Grammax

Grammax takes a grammar in BNF format as an input and converts it to a Java-class that recognizes the language generated by the grammar. Formally speaking, this tool creates a left-to-right, rightmost derivation (LR) parser for a given grammar. That means that grammax parses the given string by constructing a reversed rightmost derivation of it.

Grammax doesn’t require any external libraries or dependencies. All generation is done ahead-of-time. After generating the parsing classes you can just copy them into your project.

Also, as other good parser generation tools, grammax uses itself to read the input grammar.

Features

  • No runtime dependencies, only pure Java code is generated.
  • Parsing is done using a push-down automation without recursion.
  • Grammax uses an explicit API for accepting the token stream. It allows you to easily use the tool with any (including your own) lexer. You can pause and resume parsing at any point. Parsing multiple token streams simultaneously is also possible.
  • Grammax supports simple lr and canonical lr parsing algorithms.
  • Automatic warnings about possible right-recursion cycles that cause a lot of parsing stack memory consumption.
  • Types can be assigned to terminals and non-terminals. The corresponding expressions are casted automatically.
  • The %top statement allows inserting package and import automatically. Therefore grammax can be used in an automated pipeline.

Copyright © 2019 — 2023 Alexander Mayorov. All rights reserved.