Open this publication in new window or tab >>2021 (English)In: CC 2021: Proceedings of the 30th ACM SIGPLAN International Conference on Compiler Construction, New York, NY, United States: Association for Computing Machinery (ACM) , 2021Conference paper, Published paper (Refereed)
Abstract [en]
When building a new programming language, it can be useful to compose parts of existing languages to avoid repeating implementation work. However, this is problematic already at the syntax level, as composing the grammars of language fragments can easily lead to an ambiguous grammar. State-of-the-art parser tools cannot handle ambiguity truly well: either the grammar cannot be handled at all, or the tools give little help to an end-user who writes an ambiguous program. This composability problem is twofold: (i) how can we detect if the composed grammar is ambiguous, and (ii) if it is ambiguous, how can we help a user resolve an ambiguous program? In this paper, we depart from the traditional view of unambiguous grammar design and enable a language designer to work with an ambiguous grammar, while giving users the tools needed to handle these ambiguities. We introduce the concept of resolvable ambiguity wherein a user can resolve an ambiguous program by editing it, as well as an approach to computing the resolutions of an ambiguous program. Furthermore, we present a method based on property-based testing to identify if a composed grammar is unambiguous, resolvably ambiguous, or unresolvably ambiguous. The method is implemented in Haskell and evaluated on a large set of language fragments selected from different languages. The evaluation shows that (i) the approach can handle significantly more cases of language compositions compared to approaches which ban ambiguity altogether, and (ii) that the approach is fast enough to be used in practice.
Place, publisher, year, edition, pages
New York, NY, United States: Association for Computing Machinery (ACM), 2021
Keywords
Syntax, Ambiguity
National Category
Computer Sciences
Research subject
Computer Science
Identifiers
urn:nbn:se:kth:diva-295417 (URN)10.1145/3446804.3446846 (DOI)001436601600014 ()2-s2.0-85102312948 (Scopus ID)
Conference
CC '21: 30th ACM SIGPLAN International Conference on Compiler Construction, Online, South Korea, March 2-3, 2021
Funder
Swedish Foundation for Strategic Research, FFL15-0032Wallenberg AI, Autonomous Systems and Software Program (WASP)
Note
Part of ISBN 9781450383257
QC 20251020
2021-05-202021-05-202025-10-20Bibliographically approved