A Fast General Parser for Automatic Code Generation

  • Wuu Yang
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 6083)


The code generator in a compiler attempts to match a subject tree against a collection of tree-shaped patterns for generating instructions. Tree-pattern matching may be considered as a generalization of string parsing. We propose a new generalized LR (GLR) parser, which extends the LR parser stack with a parser cactus. GLR explores all plausible parsing steps to find the least-cost matching. GLR is fast due to two properties: (1) duplicate parsing steps are eliminated and (2) partial parse trees that will not lead to a least-cost matching are discarded as early as possible.


ambiguous grammar code generator compiler context-free grammar parsing general parsing pattern matching tree pattern tree-pattern matching 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Aho, A.V., Ganapathi, M., Tjian, S.W.K.: Code Generation Using Tree Matching and Dynamic Programming. ACM Transactions on Programming Languages and Systems 11(4), 491–516 (1989)CrossRefGoogle Scholar
  2. 2.
    Aho, A.V., Lam, M.S., Sethi, R., Ullman, J.D.: Compilers, Principles, Techniques, and Tools, 2nd edn. Addison-Wesley, New York (2007)Google Scholar
  3. 3.
    Christopher, T.W., Hatcher, P.J., Kukuk, R.C.: Using Dynamic Programming to Generate Optimized Code in a Graham-Glanville-Style Code Generator. In: Proceedings of the 1984 SIGPLAN symposium on Compiler construction, ACM SIGPLAN Notices, vol. 84, pp. 25–36. ACM, New York (1984)CrossRefGoogle Scholar
  4. 4.
    Earley, J.: An efficient context-free parsing algorithm. ACM Comm. 13(2), 94–102 (1970)zbMATHCrossRefGoogle Scholar
  5. 5.
    Fischer, C.N., LeBlanc Jr., R.J.: Crafting a Compiler with C. Benjamin/Cummings, Reading (1991)Google Scholar
  6. 6.
    Fraser, C.W., Hanson, D.R., Proebsting, T.A.: Engineering a Simple, Efficient Code Generator Generator. ACM Letters on Programming Languages and Systems 1(3), 213–226 (1992)CrossRefGoogle Scholar
  7. 7.
    Glanville, R.S.: A machine independent algorithm for code generation and its use in retargetable compilers. Ph.D. dissertation, University of California, Berkeley (December 1977)Google Scholar
  8. 8.
    Steven Glanville, R., Graham, S.L.: A new method for compiler code generation. In: Proceedings of 5th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, Tucson, Arizona, pp. 231–254 (1978)Google Scholar
  9. 9.
    Nigel Horspool, R.: An Alternative to the Graham-Glanville Code-Generation Method. IEEE Computers 20, 33–39 (1987)Google Scholar
  10. 10.
    Madhavan, M., Shankar, P.: Optimal regular tree pattern matching using pushdown automata. In: Arvind, V., Sarukkai, S. (eds.) FST TCS 1998. LNCS, vol. 1530, pp. 122–133. Springer, Heidelberg (1998)Google Scholar
  11. 11.
    Madhavan, M., Shankar, P., Rai, S., Ramakrishna, U.: Extending Graham-Glanville Techniques for Optimal Code Generation. ACM Transactions on Programming Languages and Systems 22(6), 973–1001 (2000)CrossRefGoogle Scholar
  12. 12.
    Sun Microsystems, Connected, Limited Device Configuration, Specification Version 1.0a, Java 2 Platform Micro Edition 1.0a, CA, USA (May 19, 2000)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2010

Authors and Affiliations

  • Wuu Yang
    • 1
  1. 1.National Chiao-Tung UniversityTaiwan, Republic of China

Personalised recommendations