46 research outputs found

    The Usability of Ambiguity Detection Methods for Context-Free Grammars

    Get PDF
    One way of verifying a grammar is the detection of ambiguities. Ambiguities are not always unwanted, but they can only be controlled if their sources are known. Unfortunately, the ambiguity problem for context-free grammars is undecidable in the general case. Various ambiguity detection methods (ADMs) exist, but they can never be perfect. In this paper we explore three ADMs to test whether they still can be of any practical value: the derivation generator AMBER, the LR(k) test and the Noncanonical Unambiguity test. We benchmarked their implementations on a collection of ambiguous and unambiguous grammars of different sizes and compa

    Faster ambiguity detection by grammar filtering

    Get PDF
    Real programming languages are often defined using ambiguous context-free grammars. Some ambiguity is intentional while other ambiguity is accidental. A good grammar development environment should therefore contain a static ambiguity checker to help the grammar engineer. Ambiguity of context-free grammars is an undecidable property. Nevertheless, various imperfect ambiguity checkers exist. Exhaustive methods are accurate, but suffer from non-termination. Termination is guaranteed by approximative methods, at the expense of accuracy. In this paper we combine an approximative method with an exhaustive method. We present an extension to the Noncanonical Unambiguity Test that identifies production rules that do not contribute to the ambiguity of a grammar and show how this information can be used to significantly reduce the search space of exhaustive methods. Our experimental evaluation on a number of real world grammars shows orders of magnitude gains in efficiency in some cases and negligible losses of efficiency in others

    Phrase parsers from multi-axiom grammars

    Get PDF
    AbstractMulti-axiom grammars (MAG) are alternatives to single-axiom context free grammars (CFG) and all-axiom algebraic grammars (AG) for programming language specification. Neither phrase recognition nor algebraic mechanisms for language processing are supported by CFGs. AGs support algebraic mechanisms for language processing but specify a smaller class of languages. MAGs avoid these limitations. This paper describes a new parsing algorithm developed on this basis which recognizes any phrase in the language. Moreover, it does so by distributing the parsing task among a collection of smaller parsers which handle well-defined layers of the language in a piping manner. These language-layers are determined by the algebraic properties of the MAGs and are described in the paper. Basic definitions are given for multi-axiom grammar and language as well as for algebraic notions of subgrammar, primitive subgrammar, quotient grammar, and grammar/language layer. Algorithms are described to stratify a programming language into a hierarchy of layers, to construct parsers for each layer analogous to LR construction, and to accomplish the overall task of multi-layered parsing in pipeline fashion based on a tokenization which occurs between the language layers. This pipeline parallel process is a model for high speed, left-to-right language translation

    Tracking Down the Origins of Ambiguity in Context-Free Grammars

    Get PDF
    Context-free grammars are widely used but still hindered by ambiguity. This stresses the need for detailed detection methods that point out the sources of ambiguity in a grammar. In this paper we show how the approximative Noncanonical Unambiguity Test by Schmitz can be extended to conservatively identify production rules that do not contribute to the ambiguity of a grammar. We prove the correctness of our approach and consider its practical applicability

    Tracking Down the Origins of Ambiguity in Context-Free Grammars

    Get PDF
    Context-free grammars are widely used but still hindered by ambiguity. This stresses the need for detailed detection methods that point out the sources of ambiguity in a grammar. In this paper we show how the approximative Noncanonical Unambiguity Test by Schmitz can be extended to conservatively identify production rules that do not contribute to the ambiguity of a grammar. We prove the correctness of our approach and consider its practical applicability

    Reachability and Error Diagnosis in LR(1) Parsers

    Get PDF
    International audienceGiven an LR(1) automaton, what are the states in which an error can be detected? For each such " error state " , what is a minimal input sentence that causes an error in this state? We propose an algorithm that answers these questions. This allows building a collection of pairs of an erroneous input sentence and a (handwritten) diagnostic message, ensuring that this collection covers every error state, and maintaining this property as the grammar evolves. We report on an application of this technique to the CompCert ISO C99 parser, and discuss its strengths and limitations

    Context-Free Grammars: Covers, Normal Forms, and Parsing

    Get PDF

    Context-Free Grammars: Covers, Normal Forms, and Parsing

    Get PDF
    This monograph develops a theory of grammatical covers, normal forms and parsing. Covers, formally defined in 1969, describe a relation between the sets of parses of two context-free grammars. If this relation exists then in a formal model of parsing it is possible to have, except for the output, for both grammars the same parser. Questions concerning the possibility to cover a certain grammar with grammars that conform to some requirements on the productions or the derivations will be raised and answered. Answers to these cover problems will be obtained by introducing algorithms that describe a transformation of an input grammar into an output grammar which satisfies the requirements. The main emphasis in this monograph is on transformations of context-free grammars to context-free grammars in some normal form. However, not only transformations of this kind will be discussed, but also transformations which yield grammars which have useful parsing properties
    corecore