ylmm::basic_scanner< Token, Location, id, Lock > Class Template Reference
[Lexical Scanner Classes.]

#include <ylmm/basic_scanner.hh>

Inheritance diagram for ylmm::basic_scanner< Token, Location, id, Lock >:

Inheritance graph
[legend]
Collaboration diagram for ylmm::basic_scanner< Token, Location, id, Lock >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
class ylmm::basic_scanner< Token, Location, id, Lock >

Basic scanner implementation.

This templated class implements a scanner, or rather, a specific instantation of this tempalte implmentes it. To use it, define the the processor macro YLMM_SCANNER_CLASS to a specific instance of this template, or a sub-class ofa specific instance in your Lex input file to. Note that the third argument, id can be used to disambiqutate two scanners with the same Token, Location pair. See also The Scanner Class

Parameters:
Token the type of the tokens used in the grammar.
Location the location type used, if applicable for the backend parser generator (Normal Yacc does not support that, but Bison does).
id is an integer that uniquely identifies the class.
lock The type of thread syncronisation locks used in the application. Per default a single threaded locking mechanism (that is - no locks) is used. The application should pass the appropiate type here to make the use of this class thread safe.
Examples:

simple_parser.hh, toycalc_parser.hh, and toycalc_scanner.hh.

Definition at line 380 of file basic_scanner.hh.

Public Types

typedef Token token_type
typedef Location location_type
enum  { scanner_id = id }

Public Member Functions

 basic_scanner (basic_buffer *buf=0)
template<>
int start_condition () const
template<>
int scan ()
template<>
const char * text () const
template<>
int length () const
 basic_scanner (std::istream &stream)
virtual int start_condition () const
virtual const char * text () const
virtual int length () const
virtual int scan ()
int type () const
void token (token_type &t)
void where (location_type &l, bool f=true)
virtual int next (token_type &t, location_type &l, bool f=true)
virtual int next (token_type &t)

Protected Types

typedef scanner_base< Lock > base_type

Protected Attributes

int _type
token_type _token


Member Typedef Documentation

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
typedef scanner_base<Lock> ylmm::basic_scanner< Token, Location, id, Lock >::base_type [protected]
 

Definition at line 390 of file basic_scanner.hh.

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
typedef Location ylmm::basic_scanner< Token, Location, id, Lock >::location_type
 

Type of locationss.

Definition at line 386 of file basic_scanner.hh.

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
typedef Token ylmm::basic_scanner< Token, Location, id, Lock >::token_type
 

Type of tokens.

Definition at line 384 of file basic_scanner.hh.


Member Enumeration Documentation

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
anonymous enum
 

Scanner id.

Enumerator:
scanner_id 

Definition at line 388 of file basic_scanner.hh.


Constructor & Destructor Documentation

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
ylmm::basic_scanner< Token, Location, id, Lock >::basic_scanner basic_buffer buf = 0  )  [inline]
 

Constructor.

Parameters:
buf Buffer to parse from. If null, then a buffer reading from std::cin is set up and used.

Definition at line 398 of file basic_scanner.hh.

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
ylmm::basic_scanner< Token, Location, id, Lock >::basic_scanner std::istream &  stream  )  [inline]
 

Constructor.

Parameters:
stream Stream to parse from.

Definition at line 401 of file basic_scanner.hh.


Member Function Documentation

template<>
int ylmm::basic_scanner< YLMM_SCANNER_CLASS::token_type, YLMM_SCANNER_CLASS::location_type, YLMM_SCANNER_CLASS::scanner_id, YLMM_SCANNER_CLASS::lock_type >::length  )  const [virtual]
 

Get the length of the text.

Returns:
the length of the text read

Implements ylmm::scanner_base< Lock >.

Definition at line 112 of file lexmm.hh.

References yyleng.

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
virtual int ylmm::basic_scanner< Token, Location, id, Lock >::length  )  const [virtual]
 

Get the length of the current input text.

This member function is implemented in lexmm.hh

Returns:
length of the current input text.

Implements ylmm::scanner_base< Lock >.

template<typename T, typename L, int id, typename M>
int ylmm::basic_scanner< T, L, id, M >::next token_type t  )  [inline, virtual]
 

Like above, but without the location argument.

Parameters:
t The token value to update.
Returns:
The token type number.

Definition at line 495 of file basic_scanner.hh.

References ylmm::basic_scanner< Token, Location, id, Lock >::scan(), ylmm::basic_scanner< Token, Location, id, Lock >::token(), and ylmm::basic_scanner< Token, Location, id, Lock >::type().

Here is the call graph for this function:

template<typename T, typename L, int id, typename M>
int ylmm::basic_scanner< T, L, id, M >::next token_type t,
location_type l,
bool  f = true
[inline, virtual]
 

A more generic interface to the scanner.

The parser may call this member function from it scan method to pop the next token. The point is, that often one need to do a look-up on identifiers and similar before returning the current token type to the LALR(1) parser (think typedefs in C, classes and templates in C++), so this function can be overloaded by a derived class to do that translation. The default implementation just reads a token from the input and returns the value to the caller.

Parameters:
t The token value to update.
l The location value to update.
f If true, update the mark of the region too.
Returns:
The token type number.

Definition at line 484 of file basic_scanner.hh.

References ylmm::basic_scanner< Token, Location, id, Lock >::scan(), ylmm::basic_scanner< Token, Location, id, Lock >::token(), ylmm::basic_scanner< Token, Location, id, Lock >::type(), and ylmm::basic_scanner< Token, Location, id, Lock >::where().

Here is the call graph for this function:

template<>
int ylmm::basic_scanner< YLMM_SCANNER_CLASS::token_type, YLMM_SCANNER_CLASS::location_type, YLMM_SCANNER_CLASS::scanner_id, YLMM_SCANNER_CLASS::lock_type >::scan  )  [virtual]
 

Start scanning.

Returns:
read token ID

Implements ylmm::scanner_base< Lock >.

Definition at line 87 of file lexmm.hh.

References _scanner, and yylex().

Here is the call graph for this function:

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
virtual int ylmm::basic_scanner< Token, Location, id, Lock >::scan  )  [virtual]
 

The main method of this class.

The member _type is set to the token type, and it's value is returned to the caller. Also, the internal members, _token and _location are should be set by the handlers defined in the input file to Lex. The parser may use this member function directly from ylmm::basic_parser::scan, but then it's up to the handlers to set the appropiate value of the token (and possibly the location) in the parser. See also general comments in the documentation.

Returns:
token ID number.

Implements ylmm::scanner_base< Lock >.

Referenced by ylmm::basic_scanner< Token, Location, id, Lock >::next().

template<>
int ylmm::basic_scanner< YLMM_SCANNER_CLASS::token_type, YLMM_SCANNER_CLASS::location_type, YLMM_SCANNER_CLASS::scanner_id, YLMM_SCANNER_CLASS::lock_type >::start_condition  )  const [virtual]
 

Get the start condition.

Returns:
the start condition

Implements ylmm::scanner_base< Lock >.

Definition at line 75 of file lexmm.hh.

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
virtual int ylmm::basic_scanner< Token, Location, id, Lock >::start_condition  )  const [virtual]
 

Get the current start condition.

This member function is implemented in lexmm.hh

Returns:
the current start condition.

Implements ylmm::scanner_base< Lock >.

template<>
const char * ylmm::basic_scanner< YLMM_SCANNER_CLASS::token_type, YLMM_SCANNER_CLASS::location_type, YLMM_SCANNER_CLASS::scanner_id, YLMM_SCANNER_CLASS::lock_type >::text  )  const [virtual]
 

Get the text.

Returns:
the text read

Implements ylmm::scanner_base< Lock >.

Definition at line 100 of file lexmm.hh.

References yytext.

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
virtual const char* ylmm::basic_scanner< Token, Location, id, Lock >::text  )  const [virtual]
 

Get the current input text.

This member function is implemented in lexmm.hh

Returns:
current input text.

Implements ylmm::scanner_base< Lock >.

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
void ylmm::basic_scanner< Token, Location, id, Lock >::token token_type t  )  [inline]
 

Get the last read token.

Updates the token information in place. That is, the token passed is updated to the last read token value. The token_type must be assignable.

Parameters:
t The token value.

Definition at line 439 of file basic_scanner.hh.

References ylmm::basic_scanner< Token, Location, id, Lock >::_token.

Referenced by ylmm::basic_scanner< Token, Location, id, Lock >::next().

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
int ylmm::basic_scanner< Token, Location, id, Lock >::type  )  const [inline, virtual]
 

Get the last read token type.

Returns:
last read token type.

Implements ylmm::scanner_base< Lock >.

Definition at line 433 of file basic_scanner.hh.

References ylmm::basic_scanner< Token, Location, id, Lock >::_type.

Referenced by ylmm::basic_scanner< Token, Location, id, Lock >::next().

template<typename T, typename L, int id, typename M>
void ylmm::basic_scanner< T, L, id, M >::where location_type l,
bool  f = true
[inline]
 

Get the last read position.

Updates the location information in-place in the passed argument l. If the f argument is true modify the current mark (start of region) too.

Parameters:
l The location to update in.
f If true, also update the mark to point to last point.

Definition at line 471 of file basic_scanner.hh.

References ylmm::scanner_base< Lock >::_current.

Referenced by ylmm::basic_scanner< Token, Location, id, Lock >::next().


Member Data Documentation

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
token_type ylmm::basic_scanner< Token, Location, id, Lock >::_token [protected]
 

The last token type read via yylex.

Definition at line 393 of file basic_scanner.hh.

Referenced by ylmm::basic_scanner< Token, Location, id, Lock >::token().

template<typename Token, typename Location = basic_location, int id = 0, typename Lock = basic_lock>
int ylmm::basic_scanner< Token, Location, id, Lock >::_type [protected]
 

Definition at line 391 of file basic_scanner.hh.

Referenced by ylmm::basic_scanner< Token, Location, id, Lock >::type().


The documentation for this class was generated from the following file:
Top of page
Christian Holm (home page)
Last update Fri Jul 8 12:58:04 2005
Created by DoxyGen 1.4.3-20050530