Author:
DEVRIESE DOMINIQUE,PIESSENS FRANK
Abstract
AbstractWe define a finally tagless, shallow embedding of a typed grammar language. In order to avoid the limitations of traditional parser combinator libraries (no bottom-up parsing, no full grammar analysis or transformation), we require object-language recursion to be observable in the meta-language. Since existing proposals for recursive constructs are not fully satisfactory, we propose new finally tagless primitive recursive constructs to solve the problem. To do this in a well-typed way, we require considerable infrastructure, for which we reuse techniques from the multirec generic programming library. Our infrastructure allows a precise model of the complex interaction between a grammar, a parsing algorithm and a set of semantic actions. On the flip side, our approach requires the grammar author to provide a type- and value-level encoding of the grammar's domain and we can provide only a limited form of constructs like many. We demonstrate five meta-language grammar algorithms exploiting our model, including a grammar pretty-printer, a reachability analysis, a translation of quantified recursive constructs to the standard one and an implementation of the left-corner grammar transform. The work we present forms the basis of the grammar-combinators parsing library1, which is the first to work with a precise, shallow model of abstract context-free grammars in a classical (not dependently typed) functional language and which supports a wide range of grammar manipulation primitives. From a more general point of view, our work shows a solution to the well-studied problem of observable sharing in shallowly embedded domain-specific languages and specifically in finally tagless domain-specific languages.
Publisher
Cambridge University Press (CUP)
Cited by
8 articles.
订阅此论文施引文献
订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献
1. Staged selective parser combinators;Proceedings of the ACM on Programming Languages;2020-08-02
2. Purely functional GLL parsing;Journal of Computer Languages;2020-06
3. A new view on parser combinators;Proceedings of the 31st Symposium on Implementation and Application of Functional Languages;2019-09-25
4. Derivation representation using binary subtree sets;Science of Computer Programming;2019-04
5. GLL parsing with flexible combinators;Proceedings of the 11th ACM SIGPLAN International Conference on Software Language Engineering;2018-10-24