Skip to main content


developerWorks  >  AIX and UNIX  >

Write text parsers with yacc and lex

developerWorks

Level: Intermediate

Martin Brown (mc@mcslp.com), Freelance Writer, Consultant

31 May 2006

Register now or sign in using your IBM ID and password.

Examine the processes behind building a parser using the lex/flex and yacc/bison tools, first to build a simple calculator and then delve into how you can adopt the same principles for text parsing. Parsing text -- that is, understanding and extracting the key parts of the text -- is an important part of many applications. Within UNIX®, many elements of the operating system rely on parsing text, from the shell you use to interact with the system, through to common tools and commands like awk or Perl, right through to the C compiler you use to build software and applications.

In this tutorial

  • Lexical analysis with lex

  • Grammar analysis with yacc

  • Building a calculator

  • Extending the principles of lex and yacc

Prerequisites

To use the examples in this tutorial, you will need to have access to the following tools:

  • Lex: This tool is a standard component on most UNIX operating systems. The GNU flex tool provides the same functionality.
  • Yacc: This tool is standard on most UNIX operating systems. The GNU bison tool provides the same functionality.
  • C compiler: Any standard C compiler, including Gnu CC, will be fine.
  • Make tool: This tool is required to use the sample Makefile to simplify building.
GNU tools can be downloaded from the GNU Web site, or your local GNU mirror.


System requirements

None.



Duration

2 hours


Formats

html, pdf


Share this....

digg Digg this story del.icio.us del.icio.us Slashdot Slashdot it!


Back to top


Document options

Document options requiring JavaScript are not displayed


My developerWorks needs you!

Connect to your technical community