skip to main content
article

Design patterns for parsing

Published: 23 February 2005 Publication History

Abstract

We provide a systematic transformation of an LL(1) grammar to an object model that consists of
an object structure representing the non-terminal symbols and their corresponding grammar production rules,
a union of classes representing the terminal symbols (tokens).
We present a variant form of the visitor pattern and apply it to the above union of token classes to model a predictive recursive descent parser on the given grammar. Parsing a non-terminal is represented by a visitor to the tokens. For non-terminals that have more than one production rule, the corresponding visitors are chained together according to the chain of responsibility pattern in order to be processed correctly by a valid token. The abstract factory pattern, where each concrete factory corresponds to a non-terminal symbol, is used to manufacture appropriate parsing visitors.Our object-oriented formulation for predictive recursive descent parsing eliminates the traditional construction of the predictive parsing table and yields a parser that is declarative and has minimal conditionals. It not only serves to teach standard techniques in parsing but also as a non-trivial exercise of object modeling for objects-first introductory courses.

References

[1]
Computing Curriculum 2001, Computer Science Volume, Dec. 15, 2001 (http://turing.acm.org/sigs/sigcse/cc2001/).
[2]
Madsen, Ole, Keynote speech at OOPSLA 2002, Seattle, WA, Nov. 7, 2002. (oopsla.acm.org/fp/files/spe-concepts.html).
[3]
Alphonce, C., Nguyen, D., Ventura, P. and Wong, S., "Killer Examples" for Design Patterns and Objects First Workshop, OOPSLA 2002, Seattle, WA. Nov. 4, 2002. www.cse.buffalo.edu/alphonce/OOPSLA2002/KillerExamples.
[4]
Aho, A., Sethi, R., and Ullman, J., Compilers: Principles, Techniques and Tools, Addison-Wesley, 1986.
[5]
Appel, A., Palsberg, J., Modern Compiler Implementation in Java, 2nd ed., Cambridge University Press, 2002.
[6]
Grune, D., Bal, H., Jacobs, C., and Langendoen, K., Modern Compiler Design, Wiley, 2000.
[7]
See for instance: inst.eecs.berkeley.edu/ cs164/penguin.wpi.edu:4546/course/CS544/PLT4.4.htmlwww.cs.cornell.edu/courses/cs211/2000fa/materials/Lecture09-Sept-26-Recursive-Descent-Parsing.pdfwww.cs.nyu.edu/courses/spring02/G22.2130-001/parsing1.ppthttp://www.cs.rit.edu/ hpb/Lectures/20012/LP/http://www.owlnet.rice.edu/ comp412/Lectures/09.pdf
[8]
Neff, N., OO Design in Compiling an OO Language, SIGCSE Bulletin, 31, 1, March 1999, 326--330.
[9]
Gamma, E., Helm, R., Johnson, R., and Vlissides, J. Design Patterns, Elements of Reusable Object-Oriented Software, Addison-Wesley, 1995.

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM SIGCSE Bulletin
ACM SIGCSE Bulletin  Volume 37, Issue 1
2005
562 pages
ISSN:0097-8418
DOI:10.1145/1047124
Issue’s Table of Contents
  • cover image ACM Conferences
    SIGCSE '05: Proceedings of the 36th SIGCSE technical symposium on Computer science education
    February 2005
    610 pages
    ISBN:1581139977
    DOI:10.1145/1047344
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 23 February 2005
Published in SIGCSE Volume 37, Issue 1

Check for updates

Author Tags

  1. CS1/CS2
  2. design patterns
  3. grammar
  4. modeling
  5. objects-first
  6. parsing
  7. pedagogy

Qualifiers

  • Article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)2
  • Downloads (Last 6 weeks)0
Reflects downloads up to 07 Mar 2025

Other Metrics

Citations

Cited By

View all
  • (2022)Design patterns for parser combinators in scalaProceedings of the Scala Symposium10.1145/3550198.3550427(9-21)Online publication date: 6-Jun-2022
  • (2021)Design patterns for parser combinators (functional pearl)Proceedings of the 14th ACM SIGPLAN International Symposium on Haskell10.1145/3471874.3472984(71-84)Online publication date: 18-Aug-2021
  • (2011)The nature of an object-oriented program: How do practitioners understand the nature of what they are creating?Computer Science Education10.1080/08993408.2011.60701021:3(269-287)Online publication date: Sep-2011
  • (2019)Towards A Catalog of Design Patterns Variants2019 International Conference on Frontiers of Information Technology (FIT)10.1109/FIT47737.2019.00038(156-161)Online publication date: Dec-2019
  • (2012)Using Template Metaprogramming to Enhance Reuse in Visitor-Based Model InterpretersProceedings of the 2012 IEEE 19th International Conference and Workshops on Engineering of Computer-Based Systems10.1109/ECBS.2012.48(5-14)Online publication date: 11-Apr-2012
  • (2006)Chirp on cricketsACM SIGCSE Bulletin10.1145/1124706.112137038:1(82-86)Online publication date: 3-Mar-2006
  • (2006)Chirp on cricketsProceedings of the 37th SIGCSE technical symposium on Computer science education10.1145/1121341.1121370(82-86)Online publication date: 3-Mar-2006

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media