lexer_tutorials.qbk 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Joel de Guzman
  3. Copyright (C) 2001-2011 Hartmut Kaiser
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ===============================================================================/]
  7. [section:lexer_tutorials __lex__ Tutorials Overview]
  8. The __lex__ library implements several components on top of possibly different
  9. lexer generator libraries. It exposes a pair of iterators, which, when
  10. dereferenced, return a stream of tokens generated from the underlying character
  11. stream. The generated tokens are based on the token definitions supplied by the
  12. user.
  13. Currently, __lex__ is built on top of Ben Hanson's excellent __lexertl__
  14. library (which is a proposed Boost library). __lexertl__ provides the necessary
  15. functionality to build state machines based on a set of supplied regular
  16. expressions. But __lex__ is not restricted to be used with __lexertl__. We
  17. expect it to be usable in conjunction with any other lexical scanner generator
  18. library, all what needs to be implemented is a set of wrapper objects exposing a
  19. well defined interface as described in this documentation.
  20. [note For the sake of clarity all examples in this documentation assume
  21. __lex__ to be used on top of __lexertl__.]
  22. Building a lexer using __lex__ is highly configurable, where most of this
  23. configuration is done at compile time. Almost all of the configurable
  24. parameters have generally useful default values, allowing project startup to be
  25. a easy and straightforward task. Here is a (non-complete) list of features you
  26. can tweak to adjust the generated lexer instance to the actual needs:
  27. * Select and customize the token type to be generated by the lexer instance.
  28. * Select and customize the token value types the generated token instances will
  29. be able to hold.
  30. * Select the iterator type of the underlying input stream, which will be used
  31. as the source for the character stream to tokenize.
  32. * Customize the iterator type returned by the lexer to enable debug support,
  33. special handling of certain input sequences, etc.
  34. * Select the /dynamic/ or the /static/ runtime model for the lexical
  35. analyzer.
  36. Special care has been taken during the development of the library that
  37. optimal code will be generated regardless of the configuration options
  38. selected.
  39. The series of tutorial examples of this section will guide you through some
  40. common use cases helping to understand the big picture. The first two quick
  41. start examples (__sec_lex_quickstart_1__ and __sec_lex_quickstart_2__)
  42. introduce the __lex__ library while building two stand alone applications, not
  43. being connected to or depending on any other part of __spirit__. The section
  44. __sec_lex_quickstart_3__ demonstrates how to use a lexer in conjunction with a
  45. parser (where obviously the parser is built using __qi__).
  46. [endsect]