Disambiguating Grammars with Tree Automata

Michael D. Adams and Matthew Might

Status: Published at Parsing@SLE

Abstract

Dealing with precedence and associativity rules in context free grammars (CFGs) has long posed a challenge. While they can be encoded in the structure of the CFG, the result can be difficult to work with and often obfuscates the language designer’s intent. Many parsing systems offer alternatives in the form of specialized precedence and associativity declarations, but these are limited and do not handle many similar situations such as the special rules surrounding a dangling ’else’, the precedence of ’if’ in ML, or the interactions between new and function arguments in JavaScript.

In this presentation, we show that tree automata can specify all of these while still allowing the CFG to be written in a natural man- ner. This unified theory subsumes and generalizes these other tech- niques and provides an elegant means of specifying grammatical restrictions.

When applied to an existing CFG, this technique generates a new CFG that encodes the constraints from a given tree automata. This process is closed for LR(k) and LL(k) grammars and thus can be used as a preprocessing step that is compatible with existing parsing frameworks.

Keywords

Parsing; Tree Automata

Citation

Michael D. Adams and Matthew Might. Disambiguating grammars with tree automata. In Proceedings of Parsing@SLE. ACM, New York, NY, USA, October 2015.

BibTeX Entry

@inproceedings{adams2015disambiguating,
  author = {Adams, Michael D. and Might, Matthew},
  title = {Disambiguating Grammars with Tree Automata},
  booktitle = {Proceedings of Parsing@SLE},
  year = {2015},
  address = {New York, NY, USA},
  month = oct,
  publisher = {ACM},
}