Skip to content
Per Cederberg edited this page Mar 10, 2016 · 1 revision

The basic functionality provided by this software, is also available in several other software packages. This document intends to explain the rationale for using Grammatica in comparison to other popular parser generators.

Arguments

  • Separation between source code and grammar – By separating the Java source code from the grammar, the latter gets much easier to read, and can be reused for other purposes. (SableCC also provides this.)
  • Separation between grammar and parser generator – By using a general and simple grammar file format, the grammar files are not restricted to be used by a single tool. Instead, each tool may operate differently on the grammar, supporting different subsets of functionality. The grammar files used in SableCC are free from source code, but not sufficiently generic to be of practical use elsewhere.
  • Support for LL(k) grammars – A problem with LALR(1) grammars is that it is difficult provide error recovery and good parse error messages. Using an LL(k) grammar makes this much easier. (ANTLR also provides LL(k) support.)
  • Detailed error messages – Providing detailed error messages with line and column numbers improves the usability of a parser. In particular it is important to list expected tokens as strings instead of using the internal token names. (ANTLR allows setting a description per token.)
  • Automatic error recovery – Reporting all syntax errors instantly, instead of aborting on the first one, makes a parser much easier to use. Grammatica adds such recovery automatically to generated parsers, without any changes to the grammar. (ANTLR supports error recovery by adding catch clauses to the grammar.)
  • Readable and commented source code – Although sometimes not required, at other times it is crucial to be able to understand and debug the generated parser source code.
  • Creation of parsers in run-time – By creating the parser in run-time, instead of when writing the source code, a grammar can be tested and debugged without writing a single line of code. Also, new parsers can be created dynamically in run-time without ever creating a corresponding grammar file.

Counter-arguments

  • Grammar availability – There are many freely available grammars available for download for the older parser generators. These grammars are often not too hard to modify for Grammatica, but that has not yet been done.
  • Support for LALR(1) grammars – Grammatica does not yet support LALR(1) grammars, which some other parser generators do.
  • No tokenizer modes – Tokenizer modes does not yet exist in Grammatica, but can be used in several other parser generators.
Clone this wiki locally