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

List of all members.

Public Types

typedef boost::shared_ptr< sourcepointer

Public Member Functions

 ~source ()
int getch (void)
void ungetch (int c)
void set_line_number (int n)
void error (const char *fmt,...)
void error_v (const char *fmt, va_list)
location::pointer get_location (void) const

Static Public Member Functions

static pointer create (const std::string &filename, calculator &subject)

Private Member Functions

 source (const std::string &filename, calculator &subject)
void close (void)

Private Attributes

std::string filename
calculatorsubject
FILE * fp
int line_number
bool prev_was_newline
long position
std::list< unsigned char > pushback

Detailed Description

The source class is used to represent a source file. Because we may have include files, this is used as elements on a push-down stack of sources.

Definition at line 103 of file lexer.h.


Member Typedef Documentation

typedef boost::shared_ptr<source> lexer::source::pointer

Definition at line 106 of file lexer.h.


Constructor & Destructor Documentation

The destructor. It is not virtual; thou shalt not derive from this class.

Definition at line 28 of file source.cc.

lexer::source::source ( const std::string &  filename,
calculator subject 
) [private]

The constructor. It is priovate on purpose, use the create class method instead.

Parameters:
filenameThe name of the file to be opened
subjectused to report errors.

Definition at line 34 of file source.cc.


Member Function Documentation

void lexer::source::close ( void  ) [private]

The close method is used to terminate the rest of the input. After this, getch will always return EOF.

Definition at line 60 of file source.cc.

lexer::source::pointer lexer::source::create ( const std::string &  filename,
calculator subject 
) [static]

The create class method is sued to create new dynamically allocated instances of this class.

Parameters:
filenameThe name of the file to be opened
subjectused to report errors.

Definition at line 53 of file source.cc.

void lexer::source::error ( const char *  fmt,
  ... 
)

The error method is used to report errors, including file name and line number.

Definition at line 126 of file source.cc.

void lexer::source::error_v ( const char *  fmt,
va_list  ap 
)

The error_v method is used to report errors, including file name and line number.

Definition at line 136 of file source.cc.

Definition at line 145 of file source.cc.

int lexer::source::getch ( void  )

The getch method is used to obtain the next character.

Returns:
the next charactare (0..255), or EOF at end-of-file

Definition at line 72 of file source.cc.

This is a hack so that we can report correct addresses for binary files.

Definition at line 118 of file source.cc.

void lexer::source::ungetch ( int  c)

The ungetch method may be used to returna value (obtained from getch) to the input stream. Only a single level of pushback is supported.

Parameters:
cThe value to push back (it can even cope with EOF)

Definition at line 104 of file source.cc.


Member Data Documentation

std::string lexer::source::filename [private]

The filename instance variable is used to remember the name of the file being parsed. There are two choices, logical and physical.

Definition at line 179 of file lexer.h.

FILE* lexer::source::fp [private]

The fp instance variable is used to remember the open FILE pointer, for the file we are reading. Will be NULL once EOF has been reached.

Definition at line 192 of file lexer.h.

The line_number instance variable is used to remember what line number we are currently processing, so that errors can include the filename and the line number.

Definition at line 199 of file lexer.h.

long lexer::source::position [private]

The position instance variable is used to remember the current byte position within the source file.

Definition at line 213 of file lexer.h.

The prev_was_newline instance variable is used to remember whether or not the previous character was anewline. This helps us to make sure errors are reported against the appropriate line.

Definition at line 207 of file lexer.h.

std::list<unsigned char> lexer::source::pushback [private]

The pushback instance variable is used to return one or more characters to the input.

We need this because stdio only guarantees a single character of push back, and we need several.

Definition at line 228 of file lexer.h.

The subject instance variable is used to remember the calculator instance we use to report errors.

Definition at line 185 of file lexer.h.


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