Using yacc and lex with C++

  • Authors:
  • Bruce Hahne;Hiroyuki Satō

  • Affiliations:
  • -;-

  • Venue:
  • ACM SIGPLAN Notices
  • Year:
  • 1994

Quantified Score

Hi-index 0.01

Visualization

Abstract

We consider one approach to using C++ to write a compiler in combination with the lexical analysis tool Lex and the parser generator tool YACC. This approach uses C++ classes and constructors to build a syntax tree during the parse. Synthesized and inherited attributes are easy to declare for individual terminals and nonterminals, and synthesized attributes can be computed during the parse as long as no inherited attributes are involved in the computation. We also consider the use of virtual functions for tree traversal. A complete example YACC specification is included which demonstrates these techniques. Results show that C++ offers several advantages over C for compiler design with YACC and Lex.