From abstract model to efficient compilation of patterns

  • Pär Emanuelson
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 137)


Pattern matching is a technique which is used in many application areas such as text manipulation in editors, manipulation of arithmetic formulas in computer algebra systems and in artificial intelligence applications. In programming systems it can be a built-in language facility as string matching in SNOBOL4 or a language extension for matching of list structures as in INTERLISP.

This paper presents a strategy for achieving a pattern match facility with the following properties (1) it is based on a simple model of pattern matching in order to give a good understanding for the pattern matching process (2) it is powerful, that is, it contains the union of the facilities commonly found in pattern matchers (3) it provides compilation of patterns to efficient code.

Available implementations are oriented towards providing either a clear and extensible definition of pattern matching or towards good performance at execution. The underlying problem is that good optimizing compilers are too complex to also serve as a modifiable definition of the language.

Our strategy is based on the development of a simple formal definition of the problem. Then a pattern match interpreter in Lisp is developed as an extension of the formal definition and thus serves to reach the second goal. Powerful program manipulation tools are then used to transform the interpreter according to the partial evaluation principle. The Lisp code which is the result from partial evaluation is regarded as compiled patterns.

The stepwise development of a suitable model is described and the resulting Lisp program is shown. The partial evaluation of the program with respect to one given pattern is demonstrated. Examples of optimization in the pattern language is shown and similarities between partial evaluation and lazy evaluation are pointed out. Performance results of the full implementation are given. Other approaches to pattern matching systems are briefly described and related to our approach. Finally the effects of partial evaluation on the pattern matcher are characterized and their relative importance is evaluated. The outcome of applying this strategy to similar problems is discussed.


Pattern Match Partial Evaluation Elementary Pattern Full Implementation Pattern Function 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. [BEC76]
    Beckman, L., Haraldsson, A., Oskarsson Ö., Sandewall, E., A partial evaluator and its use as a programming tool, Artificial Intelligence Journal, Vol. 7, Number 4, 1976, 319–357.Google Scholar
  2. [EMA80a]
    Emanuelson, Pär, Haraldsson, Anders, On Compiling Embedded Languages in Lisp, Proc. 1980 Lisp Conference, 1980.Google Scholar
  3. [EMA80b]
    Emanuelson, Pär, Performance enhancement in a well-structured pattern matcher through partial evaluation. Ph.D. thesis. Software Systems Research Center, Linköping University, Sweden, 1980.Google Scholar
  4. [ERS77]
    Ershov, A.P., On the partial computation principle, Information Processing Letters, Number 2, 1977.Google Scholar
  5. [FRI76]
    Friedman, D.P., Wise, D.S., CONS Should Not Evaluate Its Arguments, in Automata, Languages and Programming, S Michaelson and R. Milner (eds), Edinburgh University Press, 1976.Google Scholar
  6. [FUT71]
    Futamura, Y., Partial evaluation of computer programs: An approach to a compiler-compiler, J. Inst. Electronics and Communication Engineers, 1971.Google Scholar
  7. [GIM73]
    Gimpel, J. F., A Theory of Discrete Patterns and Their Implementation in SNOBOL4, Comm. ACM, Vol. 16, Number 2, 1973.Google Scholar
  8. [GRI71]
    Griswold, R. E., The SNOBOL4 programming language, Bell Telephone Laboratories Inc., 1971.Google Scholar
  9. [GRI76]
    Griswold, Ralph E., String Scanning in SL5, SL5 Project Document S5LD5a, The University of Arizona, Tucson, Arizona, 1976Google Scholar
  10. [GRI80]
    Griswold, Ralph E., Hanson, David R., An Alternative to the Use of Patterns in String Processing, ACM Transactions on Programming Languages and Systems, Vol 2, No 2, 1980.Google Scholar
  11. [HAR77]
    Haraldsson, Anders, A Program Manipulation System Based on Partial Evaluation, Ph. D. Thesis, Informatics Laboratory, Linköping University, Sweden, 1977.Google Scholar
  12. [HAR80]
    Haraldsson, Anders, Experiences From a Program Manipulation System, Informatics Laboratory, Linköping University, Sweden, 1980.Google Scholar
  13. [HEN76]
    Henderson, Peter, Morris, James H., A Lazy Evaluator, In Conf Rec. third Annu. ACM Symp. Principles of Programming Languages, Jan 1976.Google Scholar
  14. [MAS78]
    Masinter, Larry, The Clisp Pattern Compiler, printed in [TEI78].Google Scholar
  15. [SAC76]
    Sacerdoti, Earl D., Fikes, Richard E., Reboh, Rene, Sagalowicz, Daniel, Waldinger, Richard J., Wilber, B. Michael, Qlisp: A Language for the Interactive Development of Complex Systems, Technical Note 120, Stanford Research Institute, 1976.Google Scholar
  16. [STE75]
    Stewart, G.F., An algebraic model for string patterns. In Conf. Rec. 2nd Annu. ACM Symp. Principles of Programming Languages, Jan 1975, pp 167–184.Google Scholar
  17. [TEI67]
    Teitelman, Warren., Design and implementation of FLIP, a Lisp format directed list processor. Bolt Beranek and Newman Inc, 1967.Google Scholar
  18. [TEI78]
    Teitelman, Warren., INTERLISP reference manual, Xerox Palo Alto Research Center, Oct 1978.Google Scholar
  19. [TES73]
    Tesler, Lawrence G., Enea, Horace J., Smith David C., The LISP70 Pattern Matching System, Proc. Third International Joint Conference on Artificial Intelligence, 1973.Google Scholar
  20. [WEG76]
    Wegbreit, B., Goal-directed Program Transformation, Third ACM Symposium on Principles of Programming Languages, Atlanta, Georgia, 1976.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1982

Authors and Affiliations

  • Pär Emanuelson
    • 1
  1. 1.Software Systems Research CenterLinköping UniversityLinköpingSweden

Personalised recommendations