gfy-cpp
Loading...
Searching...
No Matches
Lexer Class Reference

A class to read tokens from a source file. More...

#include <lexer.hpp>

Public Member Functions

 Lexer (const char *filename)
 Construct a new Lexer object.
 
 Lexer (const string &filename)
 Construct a new Lexer object.
 
 ~Lexer ()
 Destroy the Lexer object.
 
Token next_token ()
 Get the next token from the source file.
 

Private Member Functions

char skip_blanks ()
 Skip blanks in the line buffer.
 
char pop_char ()
 Pop the first character from the line buffer.
 
bool is_import_line ()
 Check if the current line is an import line.
 
Type get_type (const string &identifier)
 Return the type of a given identifier.
 

Private Attributes

ifstream source
 
string filename
 
string line_buff
 
size_t line
 
size_t column
 

Static Private Attributes

static locale loc = locale(locale(), new codecvt_utf8<wchar_t>)
 

Detailed Description

A class to read tokens from a source file.

The lexer reads tokens from a source file and returns them one by one. It also keeps track of the current line and column in the source file.

Constructor & Destructor Documentation

◆ Lexer() [1/2]

Lexer::Lexer ( const char * filename)

Construct a new Lexer object.

Parameters
filenameThe name of the file to read from

◆ Lexer() [2/2]

Lexer::Lexer ( const string & filename)

Construct a new Lexer object.

Parameters
filenameThe name of the file to read from

◆ ~Lexer()

Lexer::~Lexer ( )

Destroy the Lexer object.

Member Function Documentation

◆ get_type()

Type Lexer::get_type ( const string & identifier)
private

Return the type of a given identifier.

Parameters
identifierThe identifier to check
Returns
The type of the identifier

◆ is_import_line()

bool Lexer::is_import_line ( )
private

Check if the current line is an import line.

Returns
True if the line is an import line, false otherwise

◆ next_token()

Token Lexer::next_token ( )

Get the next token from the source file.

Returns
The next token

◆ pop_char()

char Lexer::pop_char ( )
private

Pop the first character from the line buffer.

Returns
The first character of the line buffer

◆ skip_blanks()

char Lexer::skip_blanks ( )
private

Skip blanks in the line buffer.

Returns
The first non-blank character

Field Documentation

◆ column

size_t Lexer::column
private

◆ filename

string Lexer::filename
private

◆ line

size_t Lexer::line
private

◆ line_buff

string Lexer::line_buff
private

◆ loc

locale Lexer::loc = locale(locale(), new codecvt_utf8<wchar_t>)
staticprivate

◆ source

ifstream Lexer::source
private

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