Reference. Validating LR(1) Parsers
Cite
Cited by (12)
Intrinsic Verification of Parsers and Formal Grammar Theory in Dependent Lambek Calculus intrinsic-verification-of-parsers
We present Dependent Lambek Calculus (Lambek), a domain-specific dependent type theory for verified parsing and formal grammar theory. In Lambek, linear types are used as a syntax for formal grammars, and parsers can be written as linear terms. The linear typing restriction provides a form of intrinsic verification that a parser yields only valid parse trees for the input string. We demonstrate the expressivity of this system by showing that the combination of inductive linear types and dependency on non-linear data can be used to encode commonly used grammar formalisms such as regular and context-free grammars as well as traces of various types of automata. Using these encodings, we define parsers for regular expressions using deterministic automata, as well as examples of verified parsers of context-free grammars.
We present a denotational semantics of our type theory that interprets the linear types as functions from strings to sets of abstract parse trees and terms as parse transformers. Based on this denotational semantics, we have made a prototype implementation of Lambek using a shallow embedding in the Agda proof assistant. All of our examples parsers have been implemented in this prototype implementation.
Coqlex: Generating formally verified lexers Ouedraogo_2023
A compiler consists of a sequence of phases going from lexical analysis to code generation. Ideally, the formal verification of a compiler should include the formal verification of each component of the tool-chain. An example is the CompCert project, a formally verified C compiler, that comes with associated tools and proofs that allow to formally verify most of those components.
However, some components, in particular the lexer, remain unverified. In fact, the lexer of Compcert is generated using OCamllex, a lex-like OCaml lexer generator that produces lexers from a set of regular expressions with associated semantic actions. Even though there exist various approaches, like CakeML or Verbatim++, to write verified lexers, they all have only limited practical applicability.
In order to contribute to the end-to-end verification of compilers, we implemented a generator of verified lexers whose usage is similar to OCamllex. Our software, called Coqlex, reads a lexer specification and generates a lexer equipped with a Coq proof of its correctness. It provides a formally verified implementation of most features of standard, unverified lexer generators.
The conclusions of our work are two-fold: Firstly, verified lexers gain to follow a user experience similar to lex/flex or OCamllex, with a domain-specific syntax to write lexers comfortably. This introduces a small gap between the written artifact and the verified lexer, but our design minimizes this gap and makes it practical to review the generated lexer. The user remains able to prove further properties of their lexer. Secondly, it is possible to combine simplicity and decent performance. Our implementation approach that uses Brzozowski derivatives is noticeably simpler than the previous work in Verbatim++ that tries to generate a deterministic finite automaton (DFA) ahead of time, and it is also noticeably faster thanks to careful design choices.
We wrote several example lexers that suggest that the convenience of using Coqlex is close to that of standard verified generators, in particular, OCamllex. We used Coqlex in an industrial project to implement a verified lexer of Ada. This lexer is part of a tool to optimize safety-critical programs, some of which are very large. This experience confirmed that Coqlex is usable in practice, and in particular that its performance is good enough. Finally, we performed detailed performance comparisons between Coqlex, OCamllex, and Verbatim++. Verbatim++ is the state-of-the-art tool for verified lexers in Coq, and the performance of its lexer was carefully optimized in previous work by Egolf and al. (2022). Our results suggest that Coqlex is two orders of magnitude slower than OCamllex, but two orders of magnitude faster than Verbatim++.
Verified compilers and other language-processing tools are becoming important tools for safety-critical or security-critical applications. They provide trust and replace more costly approaches to certification, such as manually reading the generated code. Verified lexers are a missing piece in several Coq-based verified compilers today. Coqlex comes with safety guarantees, and thus shows that it is possible to build formally verified front-ends.
Verified ALL(*) Parsing with Semantic Actions and Dynamic Input Validation lasserCoStar2023
Verbatim++: verified, optimized, and semantically rich lexing with derivatives egolf-2022-verbatim
CoStar: A verified ALL(*) parser lasserCoStarVerifiedALL2021
Zippy LL(1) parsing with derivatives EdelmannZippy2020
QED at Large: A Survey of Engineering of Formally Verified Software ringer-2019-qed
A Verified LL(1) Parser Generator lasserLL1_2019
Reasonably programmable literal notation omar-2018-reasonably
agdarsec — total parser combinators allais_2018
Certified Normalization of Context-Free Grammars firsovCertifiedNormalizationContextFree2015
CakeML: A verified implementation of ML kumar_cakeml_2014
Cites 25 works (2 here)
With notes (2)
Formal verification of a realistic compiler leroy_formal_2009
On the translation of languages from left to right KNUTH1965607
External (23)
- Coq code for validating LR(1) parsers (2012)
- TRX: A Formally Verified Parser Interpreter (2011)
- A formalisation of the theory of context-free languages in higher order logic (Barthwal, PhD thesis, ANU) (2010)
- A simple, verified validator for software pipelining (2010)
- Verified, Executable Parsing (2009)
- Parsing C/C++ Code without Pre-processing (2009)
- Certified web services in Ynot (2009)
- Packrat parsers can support left recursion (2008)
- Program-ing finger trees in Coq (2007)
- ISO/IEC 9899:TC3 Programming languages — C (2007)
- Towards Efficient, Typed LR Parsers (2006)
- A machine-checked model for a Java-like language, virtual machine, and compiler (2006)
- Parsing expression grammars: a recognition-based syntactic foundation (2004)
- Functors for Proofs and Programs (2004)
- Packrat parsing: simple, powerful, lazy, linear time (2002)
- Translation validation for an optimizing compiler (2000)
- Translation validation (1998)
- A practical general method for constructing LR(k) parsers (1977)
- Automatically Proving the Correctness of Translations Involving Optimized Code (Samet, PhD thesis) (1975)
- Efficient LR(1) parsers (1973)
- The theory of parsing, translation, and compiling (1972)
- Simple LR(k) grammars (1971)
- The Menhir parser generator