1. Resolvable ambiguity: principled resolution of syntactically ambiguous programs
- Author
-
Philipp Haller, David Broman, Viktor Palmkvist, and Elias Castegren
- Subjects
Ambiguity ,050101 languages & linguistics ,Computer science ,media_common.quotation_subject ,02 engineering and technology ,computer.software_genre ,Rule-based machine translation ,0202 electrical engineering, electronic engineering, information engineering ,0501 psychology and cognitive sciences ,Syntax ,computer.programming_language ,media_common ,Parsing ,Syntax (programming languages) ,Grammar ,Computer Sciences ,business.industry ,05 social sciences ,Resolution (logic) ,Datavetenskap (datalogi) ,Ambiguous grammar ,020201 artificial intelligence & image processing ,Haskell ,Artificial intelligence ,business ,computer ,Natural language processing - Abstract
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. Part of proceedings: ISBN 9781450383257, QC 20230117
- Published
- 2021
- Full Text
- View/download PDF