From Context-free Grammars with Priorities to Character Class Grammars

Eelco Visser. From Context-free Grammars with Priorities to Character Class Grammars. Technical Report P9717, Programming Research Group, University of Amsterdam, Amsterdam, The Netherlands, October 1997.


Priority and associativity declarations are used to disambiguate ambiguous fragments of context-free grammars. Usually this concerns expression grammars. It is possible to describe the same language by means of an ambiguous context-free grammar only, but using auxiliary non-terminals and extra chain productions resulting in a grammar that generates different and larger trees and extra parse steps.

In this paper we introduce a grammar transformation that translates a context-free grammar with priorities to a character class grammar that does only generate trees without priority conflicts. The transformed grammar has the property that each production corresponds to a production in the original grammar and that no extra productions are used. The parse trees over the transformed grammar are therefore isomorphic to parse trees over the original grammar.