Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

Lexer Class Reference

#include <interpret.h>

Inheritance diagram for Lexer:

Inheritance graph
[legend]

Public Member Functions

 Lexer (const string &aBuffer)
 ~Lexer (void)
virtual const int GetTopSymbol (void)
virtual const char atSr (const int ati, const int atj)=0
virtual const int EofId (void) const=0
virtual const int IdentifierId (void) const=0
virtual const int NumberId (void) const=0
const bool IsReal (void) const
const string & GetConstant (void) const

Data Fields

int lineno
std::map< string, int, greater<
string > > 
symbol

Protected Member Functions

virtual const bool isSeparator (void)
virtual const int SkipComment (void)
virtual const int LexNext (void)
virtual const int GetIdentifier (void)
virtual const int GetNumber (void)

Private Attributes

const string & buffer
string::size_type at
string::size_type bufLen
string constantStr
bool realConstant

Constructor & Destructor Documentation

Lexer::Lexer const string &  aBuffer  ) 
 

Definition at line 3 of file interpret.cpp.

00004 : buffer( aBuffer ) , bufLen( aBuffer.length() ) , at( 0 ) , lineno( 0 )
00005 {
00006 }

Lexer::~Lexer void   )  [inline]
 

Definition at line 23 of file interpret.h.

00023 {};


Member Function Documentation

virtual const char Lexer::atSr const int  ati,
const int  atj
[pure virtual]
 

Implemented in Ars::ExprInt, Expr, and Ars::ExprInt.

Referenced by Interpret::Run().

virtual const int Lexer::EofId void   )  const [pure virtual]
 

Implemented in Ars::ExprInt, Expr, and Ars::ExprInt.

Referenced by Interpret::Initialize(), and SkipComment().

const string& Lexer::GetConstant void   )  const [inline]
 

Definition at line 33 of file interpret.h.

References constantStr.

Referenced by Interpret::Run(), and Interpret::ShiftRule().

00033 {       return constantStr;     }

const int Lexer::GetIdentifier void   )  [protected, virtual]
 

Definition at line 66 of file interpret.cpp.

References at, buffer, constantStr, and IdentifierId().

Referenced by LexNext().

00067 {
00068         while( isalnum( buffer[at] ) || buffer[at] == '_' )
00069                 constantStr += buffer[at++];
00070 
00071         return IdentifierId();
00072 }

const int Lexer::GetNumber void   )  [protected, virtual]
 

Definition at line 74 of file interpret.cpp.

References at, buffer, constantStr, NumberId(), and realConstant.

Referenced by LexNext().

00075 {
00076         while( isdigit( buffer[at] ) )
00077                 constantStr += buffer[at++];
00078         if( buffer[at] == '.' )
00079         {
00080                 at += 1;
00081                 realConstant = true;
00082                 constantStr += '.';
00083                 while( isdigit( buffer[at] ) )
00084                         constantStr += buffer[at++];
00085         }
00086         return NumberId();
00087 }

const int Lexer::GetTopSymbol void   )  [virtual]
 

Definition at line 8 of file interpret.cpp.

References at, constantStr, isSeparator(), realConstant, and SkipComment().

Referenced by Interpret::Run(), and SkipComment().

00009 {
00010         realConstant = false;
00011         constantStr.clear();
00012 
00013         while( isSeparator() )
00014                 at++;
00015 
00016         return SkipComment();
00017 }

virtual const int Lexer::IdentifierId void   )  const [pure virtual]
 

Implemented in Ars::ExprInt, Expr, and Ars::ExprInt.

Referenced by GetIdentifier().

const bool Lexer::IsReal void   )  const [inline]
 

Definition at line 32 of file interpret.h.

References realConstant.

00032 {       return realConstant;    }

const bool Lexer::isSeparator void   )  [protected, virtual]
 

Definition at line 19 of file interpret.cpp.

References at, buffer, bufLen, and lineno.

Referenced by GetTopSymbol().

00020 {
00021         if( at < bufLen && buffer.substr( at , 1 ).find_first_of( "\n\r\t " ) != string::npos )
00022         {
00023                 if( buffer[at] == '\n' )
00024                         lineno += 1;
00025                 return true;
00026         }
00027         return false;
00028 }

const int Lexer::LexNext void   )  [protected, virtual]
 

Definition at line 48 of file interpret.cpp.

References at, buffer, constantStr, GetIdentifier(), GetNumber(), and symbol.

Referenced by SkipComment().

00049 {
00050         for( map<string,int,greater<string> >::iterator it = symbol.begin() ; it != symbol.end() ; ++it )
00051                 if( buffer.substr( at , it->first.length() ) == it->first )
00052                 {
00053                         constantStr = it->first;
00054                         at += it->first.length();
00055                         return it->second;
00056                 }
00057 
00058         if( isalpha( buffer[at] ) )
00059                 return GetIdentifier();
00060         else if( isdigit( buffer[at] ) )
00061                 return GetNumber();
00062 
00063         return -1;
00064 }

virtual const int Lexer::NumberId void   )  const [pure virtual]
 

Implemented in Ars::ExprInt, Expr, and Ars::ExprInt.

Referenced by GetNumber().

const int Lexer::SkipComment void   )  [protected, virtual]
 

Definition at line 30 of file interpret.cpp.

References at, buffer, bufLen, EofId(), GetTopSymbol(), and LexNext().

Referenced by GetTopSymbol().

00031 {
00032         if( at > bufLen )
00033                 return -1;
00034         else if( at == bufLen )
00035         {
00036                 at += 1;
00037                 return EofId();
00038         }
00039         else if( (at + 2) < bufLen && buffer.substr( at , 2 ) == "//" )
00040         {
00041                 at = buffer.find( '\n' , at );
00042                                   
00043                 return GetTopSymbol();
00044         }
00045         return LexNext();
00046 }


Field Documentation

string::size_type Lexer::at [private]
 

Definition at line 10 of file interpret.h.

Referenced by GetIdentifier(), GetNumber(), GetTopSymbol(), isSeparator(), LexNext(), and SkipComment().

const string& Lexer::buffer [private]
 

Definition at line 9 of file interpret.h.

Referenced by GetIdentifier(), GetNumber(), isSeparator(), LexNext(), and SkipComment().

string::size_type Lexer::bufLen [private]
 

Definition at line 10 of file interpret.h.

Referenced by isSeparator(), and SkipComment().

string Lexer::constantStr [private]
 

Definition at line 12 of file interpret.h.

Referenced by GetConstant(), GetIdentifier(), GetNumber(), GetTopSymbol(), and LexNext().

int Lexer::lineno
 

Definition at line 17 of file interpret.h.

Referenced by isSeparator().

bool Lexer::realConstant [private]
 

Definition at line 13 of file interpret.h.

Referenced by GetNumber(), GetTopSymbol(), and IsReal().

std::map<string,int,greater<string> > Lexer::symbol
 

Definition at line 19 of file interpret.h.

Referenced by Expr::Expr(), Ars::ExprInt::ExprInt(), and LexNext().


The documentation for this class was generated from the following files:
Generated on Fri Dec 5 04:06:24 2003 for Borqueror by doxygen 1.3.3