Layout Syntax Support in the BNF Converter

Typ
Examensarbete för masterexamen
Master's Thesis
Program
Computer science – algorithms, languages and logic (MPALG), MSc
Publicerad
2023
Författare
Burreau, Beata
Modellbyggare
Tidskriftstitel
ISSN
Volymtitel
Utgivare
Sammanfattning
Many programming languages, such as Haskell and Python, use layout as part of their syntax. We can expect future programming languages to also be layoutsensitive. Therefore, the toolchains for implementing programming languages must support layout-sensitive languages. This thesis presents a declarative approach to describing layout-sensitive languages and parsing programs written in them. We reserve the terminals newline, indent, and dedent for describing layout syntax in BNF grammar and provide an algorithm for representing the layout of a program with these terminals, before parsing it. By verbalising layout syntax this way, mainstream parser generators, and their parsing algorithms, can be used. This approach is successfully implemented in BNF Converter (BNFC), a tool that generates a compiler front-end from a context-free grammar in Labelled BNF (LBNF) form. With a special kind of LBNF rule, called pragma, it is possible to declare global layout syntax rules, such as the offside rule, which affects the insertion of layout terminals by the aforementioned algorithm. The reserved terminals and the pragmas can together describe popular layout syntax. Furthermore, both purely layout-sensitive languages and those mixing layoutsensitive and insensitive syntax are describable in LBNF.
Beskrivning
Ämne/nyckelord
layout , syntax , indentation-sensitive language , context-free grammar , Labelled BNF (LBNF) , BNF Converter (BNFC) , Pfenning safety
Citation
Arkitekt (konstruktör)
Geografisk plats
Byggnad (typ)
Byggår
Modelltyp
Skala
Teknik / material
Index