Validating LR(1) Parsers

  • Jacques-Henri Jourdan
  • François Pottier
  • Xavier Leroy
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7211)

Abstract

An LR(1) parser is a finite-state automaton, equipped with a stack, which uses a combination of its current state and one lookahead symbol in order to determine which action to perform next. We present a validator which, when applied to a context-free grammar \(\mathcal G\) and an automaton \(\mathcal A\), checks that \(\mathcal A\) and \(\mathcal G\) agree. Validating the parser provides the correctness guarantees required by verified compilers and other high-assurance software that involves parsing. The validation process is independent of which technique was used to construct \(\mathcal A\). The validator is implemented and proved correct using the Coq proof assistant. As an application, we build a formally-verified parser for the C99 language.

References

  1. 1.
    Leroy, X.: Formal verification of a realistic compiler. Communications of the ACM 52, 107–115 (2009)CrossRefGoogle Scholar
  2. 2.
    Barthwal, A., Norrish, M.: Verified, Executable Parsing. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 160–174. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  3. 3.
    Barthwal, A.: A formalisation of the theory of context-free languages in higher order logic. PhD thesis, Australian National University (December 2010)Google Scholar
  4. 4.
    DeRemer, F.L.: Simple LR(k) grammars. Communications of the ACM 14(7), 453–460 (1971)MathSciNetMATHCrossRefGoogle Scholar
  5. 5.
    Anderson, T., Eve, J., Horning, J.J.: Efficient LR(1) parsers. Acta Informatica 2, 12–39 (1973)MathSciNetMATHCrossRefGoogle Scholar
  6. 6.
    Pager, D.: A practical general method for constructing LR(k) parsers. Acta Informatica 7, 249–268 (1977)MathSciNetMATHCrossRefGoogle Scholar
  7. 7.
    Knuth, D.E.: On the translation of languages from left to right. Information & Control 8, 607–639 (1965)MathSciNetCrossRefGoogle Scholar
  8. 8.
    Pottier, F., Régis-Gianas, Y.: The Menhir parser generator, http://gallium.inria.fr/~fpottier/menhir/
  9. 9.
    Jourdan, J.H., Pottier, F., Leroy, X.: Coq code for validating LR(1) parsers, http://www.eleves.ens.fr/home/jjourdan/parserValidator.tgz
  10. 10.
    Filliâtre, J.-C., Letouzey, P.: Functors for Proofs and Programs. In: Schmidt, D. (ed.) ESOP 2004. LNCS, vol. 2986, pp. 370–384. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  11. 11.
    ISO/IEC: Programming languages — C (2007) International standard ISO/IEC 9899:TC3Google Scholar
  12. 12.
    Padioleau, Y.: Parsing C/C++ Code without Pre-processing. In: de Moor, O., Schwartzbach, M.I. (eds.) CC 2009. LNCS, vol. 5501, pp. 109–125. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  13. 13.
    Pottier, F., Régis-Gianas, Y.: Towards efficient, typed LR parsers. Electronic Notes in Theoretical Computer Science 148(2), 155–180 (2006)CrossRefGoogle Scholar
  14. 14.
    Ford, B.: Packrat parsing: simple, powerful, lazy, linear time. In: ACM International Conference on Functional Programming (ICFP), pp. 36–47 (October 2002)Google Scholar
  15. 15.
    Ford, B.: Parsing expression grammars: a recognition-based syntactic foundation. In: ACM Symposium on Principles of Programming Languages (POPL), pp. 111–122 (January 2004)Google Scholar
  16. 16.
    Warth, A., Douglass, J.R., Millstein, T.D.: Packrat parsers can support left recursion. In: ACM Workshop on Evaluation and Semantics-Based Program Manipulation (PEPM), pp. 103–110 (January 2008)Google Scholar
  17. 17.
    Koprowski, A., Binsztok, H.: TRX: A formally verified parser interpreter. Logical Methods in Computer Science 7 (2011)Google Scholar
  18. 18.
    Wisnesky, R., Malecha, G., Morrisett, G.: Certified web services in Ynot. In: Workshop on Automated Specification and Verification of Web Systems (July 2009)Google Scholar
  19. 19.
    Samet, H.: Automatically Proving the Correctness of Translations Involving Optimized Code. PhD thesis, Stanford University (1975)Google Scholar
  20. 20.
    Pnueli, A., Siegel, M., Singerman, E.: Translation Validation. In: Steffen, B. (ed.) TACAS 1998. LNCS, vol. 1384, pp. 151–166. Springer, Heidelberg (1998)CrossRefGoogle Scholar
  21. 21.
    Necula, G.C.: Translation validation for an optimizing compiler. In: ACM Conference on Programming Language Design and Implementation (PLDI), pp. 83–95. ACM Press (2000)Google Scholar
  22. 22.
    Tristan, J.B., Leroy, X.: A simple, verified validator for software pipelining. In: ACM Symposium on Principles of Programming Languages (POPL), pp. 83–92. ACM Press (2010)Google Scholar
  23. 23.
    Klein, G., Nipkow, T.: A machine-checked model for a Java-like language, virtual machine and compiler. ACM Transactions on Programming Languages and Systems 28, 619–695 (2006)CrossRefGoogle Scholar
  24. 24.
    Aho, A.V., Ullman, J.D.: The theory of parsing, translation, and compiling. Prentice-Hall (1972)Google Scholar
  25. 25.
    Sozeau, M.: Program-ing finger trees in Coq. In: ACM International Conference on Functional Programming (ICFP), pp. 13–24 (September 2007)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Jacques-Henri Jourdan
    • 1
    • 2
  • François Pottier
    • 2
  • Xavier Leroy
    • 2
  1. 1.École Normale SupérieureFrance
  2. 2.INRIA Paris-RocquencourtFrance

Personalised recommendations