Gyoji Compiler
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Gyoji::context::Token Class Reference

Represents a token read from the input stream. More...

#include <token-stream.hpp>

Public Member Functions

 Token (TokenID _typestr, std::string _value, const std::string &_filename, size_t _line, size_t _column, size_t _length)
 
 ~Token ()
 
const TokenID & get_type () const
 
const std::stringget_value () const
 

Detailed Description

Represents a token read from the input stream.

A token represents the result of the lexical analysis and contains the line number and column number of where the token was found as well as the type of token and the literal value of the token from the input. Some tokens participate in the grammar such as language keywords while others represent whitespace or comments.

While it might seem that this belongs in the lex/parse code of the front-end, this token is less concrete in the sense that it is actually agnostic of the way the data is broken up and parsed. This token stream can actually be re-used for multiple different lexical and syntactical structures.

It also carries the source location where the token was read from so that its source-reference can be used to derive and report the location of any errors. It is declared in the compiler context because the token stream must have a lifetime at least as long as the error reporting system because the errors hold references to the tokens and their source references.

Constructor & Destructor Documentation

◆ Token()

Token::Token ( TokenID  _typestr,
std::string  _value,
const std::string _filename,
size_t  _line,
size_t  _column,
size_t  _length 
)

Creates a new token of the given type and value with the line number and column number where it was found in the input stream.

◆ ~Token()

Token::~Token ( )

Destructor, nothing fancy.

Member Function Documentation

◆ get_type()

const TokenID & Token::get_type ( ) const

This returns the type of the token. In most cases, this will be the token symbol from the grammar definition but in some cases may refer to a whitespace or comment directly from the input and bypassing the grammar entirely.

◆ get_value()

const std::string & Token::get_value ( ) const

This is the literal value that was found in the input stream and matched one of the lexical rules.


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