Canola  0.8.D001
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
lexer Class Reference

#include <lexer.h>

List of all members.

Classes

class  source

Public Member Functions

virtual ~lexer ()
 lexer (const std::string &filename, calculator &subject)
bool read_and_execute (void)
bool read_binary_and_execute (void)
void test_mode_set (bool state=true)

Static Public Member Functions

static void search_path_append (const std::string &dir)

Private Types

typedef boost::shared_ptr
< lexer_functor
functor_pointer
typedef std::map< std::string,
functor_pointer
names_t

Private Member Functions

void close (void)
bool next_is (char c)
bool next_is (const char *s)
int getch (void)
void ungetch (int c)
void error (const char *fmt,...)
void open_include_file (const std::string &filename)
void load_names (void)
location::pointer get_location (void) const
location::pointer get_location (const location::pointer &start) const
void process_comment (const std::string &text)
 lexer ()
 lexer (const lexer &)
lexeroperator= (const lexer &)

Private Attributes

calculatorsubject
std::list< source::pointersrc
bool test_mode
names_t names
bool card_properties_active
bool ok

Static Private Attributes

static search_path include_search_path

Detailed Description

The lexer class is used to represent the processing required to read and understand a script file. This file contains mnem,onics for each of the keys, and passes them to a calculator instance to execute.

Definition at line 40 of file lexer.h.


Member Typedef Documentation

typedef boost::shared_ptr<lexer_functor> lexer::functor_pointer [private]

Definition at line 310 of file lexer.h.

typedef std::map<std::string, functor_pointer> lexer::names_t [private]

Definition at line 311 of file lexer.h.


Constructor & Destructor Documentation

lexer::~lexer ( ) [virtual]

The destructor.

Definition at line 33 of file lexer.cc.

lexer::lexer ( const std::string &  filename,
calculator subject 
)

The constructor.

Definition at line 39 of file lexer.cc.

lexer::lexer ( ) [private]

The default constructor. Do not use.

lexer::lexer ( const lexer ) [private]

The copy constructor. Do not use.


Member Function Documentation

void lexer::close ( void  ) [private]

The close method is used to close all open input files. All subsequent getch calls will report EOF.

Definition at line 49 of file lexer.cc.

void lexer::error ( const char *  fmt,
  ... 
) [private]

The error method is used to report errors to the subject. It will include file filename and line number.

Parameters:
fmtThe error format, and it describes the number and types o the remaining arguments.

Definition at line 787 of file lexer.cc.

location::pointer lexer::get_location ( void  ) const [private]

The get_location method is used to obtain the present location within the text of the programme. It has zero width.

Definition at line 820 of file lexer.cc.

location::pointer lexer::get_location ( const location::pointer start) const [private]

The get_location method is used to obtain the present location within the text of the programme.

Parameters:
startrelative to this start location, to set the width.

Definition at line 830 of file lexer.cc.

int lexer::getch ( void  ) [private]

The getch method is used to obtain the next character if input, or EOF if all inpout files, including include files, have been exhausted.

Definition at line 64 of file lexer.cc.

void lexer::load_names ( void  ) [private]

The load_names method is used to populate the names instance variable, when needed.

Definition at line 144 of file lexer.cc.

bool lexer::next_is ( char  c) [private]

The next_is method is used to see if the next character is the character given. If it is, that character of input is consumed; if not, no input is consumed.

Parameters:
cThe character of interest.

Definition at line 88 of file lexer.cc.

bool lexer::next_is ( const char *  s) [private]

The next_is method is used to see if the next few characters are the string given. If it is, thise characters of input are consumed; if not, no input is consumed.

Parameters:
sThe character string of interest.

Definition at line 101 of file lexer.cc.

void lexer::open_include_file ( const std::string &  filename) [private]

The open_include_file method is used internally to open include files. They are permitted to be nested.

Parameters:
filenameThe name of the file to be included.

Definition at line 56 of file lexer.cc.

lexer& lexer::operator= ( const lexer ) [private]

The assignment operator. Do not use.

void lexer::process_comment ( const std::string &  text) [private]

The process_comment method is used to process the text of a comment, looking for card properties.

Parameters:
textThe text body of the comment (without the introducer character).

Definition at line 477 of file lexer.cc.

bool lexer::read_and_execute ( void  )

The read_and_execute method is used to read the named text file, and decode the opcodes therein, passing them to the given subject.

Returns:
True if no errors, false if at least one error.

Definition at line 507 of file lexer.cc.

The read_binary_and_execute method is used to read the named binary file, and decode the opcodes therein, passing them to the given subject.

Returns:
True if no errors, false if at least one error.

Definition at line 745 of file lexer.cc.

void lexer::search_path_append ( const std::string &  dir) [static]

The search_path_append class method is used to append another directory to the list of directories search for include files.

Definition at line 806 of file lexer.cc.

void lexer::test_mode_set ( bool  state = true)

The test_mode_set method is used to force the lexer into "test mode" where you can enter more things to drive the calculator state. Must be called before the read_and_execute method to have any effect.

Parameters:
stateThe state of test_mode to set

Definition at line 813 of file lexer.cc.

void lexer::ungetch ( int  c) [private]

The ungetc method is used to return a character (previously obtain from the getch method) to the input.

Parameters:
cThe character to be returned (it can even cope with EOF).

Definition at line 80 of file lexer.cc.


Member Data Documentation

The card_properties_active instance variable is used to remember whether or not we are between "Card-Pocket-Begin" and "Card-Pocket-End" comment lines.

Definition at line 345 of file lexer.h.

The include_search_path class variable is used to remember the list of directories to be searched for include files.

Definition at line 308 of file lexer.h.

names_t lexer::names [private]

The names insrtance variable is used to remember the table of names and corresponding actions, when parsing text files.

Definition at line 317 of file lexer.h.

bool lexer::ok [private]

The ok instance variable is used to remember whether or not an error has ocurred when processing a file. True means no error, false means at least one error.

Definition at line 361 of file lexer.h.

std::list<source::pointer> lexer::src [private]

The src instance variable is used to remember the stack of data sources. Include files are pushed onto this stack.

Definition at line 235 of file lexer.h.

The subject instance variable is used to remember the claculator that is to receive the code stream, and is also used to report errors.

Definition at line 96 of file lexer.h.

bool lexer::test_mode [private]

The test_mode instance variable is used to remember whether or not we are operating on test mode.

Definition at line 241 of file lexer.h.


The documentation for this class was generated from the following files: