User Guide
nmodl::ModToken Class Reference

Represent token returned by scanner. More...

Detailed Description

Represent token returned by scanner.

Every token returned by lexer is represented by ModToken. Some tokens are also externally defined names like dt, t. These names are defined in NEURON and hence we set external property to true. Also, location class represent the position of the token in nmodl file. By default location is initialized to line,column as 1,1. Some tokens are explicitly added during compiler passes. Hence we set the position to 0,0 so that we can distinguish them from other tokens produced by lexer.

Todo:
  • LocationType object is copyable except if we specify the stream name. It would be good to track filename when we go for multi-channel optimization and code generation.
See also

Definition at line 50 of file modtoken.hpp.

#include <modtoken.hpp>

Public Member Functions

ModTokenclone () const
 Return a new instance of token. More...
 
std::string text () const
 Return token text from mod file. More...
 
int type () const
 Return token type from lexer. More...
 
int start_line () const
 Return line number where token started in the mod file. More...
 
int start_column () const
 Return start of column number where token appear in the mod file. More...
 
std::string position () const
 Return position of the token as string. More...
 
Ctor & dtor
 ModToken ()
 
 ModToken (bool ext)
 
 ModToken (std::string name, int token, LocationType &pos)
 

Private Types

using LocationType = nmodl::parser::location
 

Private Attributes

std::string name
 name of the token More...
 
int token = -1
 token value returned by lexer More...
 
LocationType pos
 position of token in the mod file More...
 
bool external = false
 true if token is externally defined variable (e.g. t, dt in NEURON) More...
 

Friends

std::ostream & operator<< (std::ostream &stream, const ModToken &mt)
 Overload << operator to print object. More...
 
ModToken operator+ (ModToken const &adder1, ModToken const &adder2)
 Overload + operator to create an object whose position starts from the start line and column of the first adder and finishes at the end line and column of the second adder. More...
 

Member Typedef Documentation

◆ LocationType

using nmodl::ModToken::LocationType = nmodl::parser::location
private

Definition at line 51 of file modtoken.hpp.

Constructor & Destructor Documentation

◆ ModToken() [1/3]

nmodl::ModToken::ModToken ( )
inline

Definition at line 70 of file modtoken.hpp.

◆ ModToken() [2/3]

nmodl::ModToken::ModToken ( bool  ext)
inlineexplicit

Definition at line 73 of file modtoken.hpp.

◆ ModToken() [3/3]

nmodl::ModToken::ModToken ( std::string  name,
int  token,
LocationType pos 
)
inline

Definition at line 77 of file modtoken.hpp.

Member Function Documentation

◆ clone()

ModToken* nmodl::ModToken::clone ( ) const
inline

Return a new instance of token.

Definition at line 85 of file modtoken.hpp.

◆ position()

std::string nmodl::ModToken::position ( ) const

Return position of the token as string.

This is used used by other passes like scope checker to print the location of token in mod files :

  • external token position : [EXTERNAL]
  • token with unknown position : [UNKNOWN]
  • token with known position : [line_num.start_column-end_column]

Definition at line 14 of file modtoken.cpp.

◆ start_column()

int nmodl::ModToken::start_column ( ) const
inline

Return start of column number where token appear in the mod file.

Definition at line 105 of file modtoken.hpp.

◆ start_line()

int nmodl::ModToken::start_line ( ) const
inline

Return line number where token started in the mod file.

Definition at line 100 of file modtoken.hpp.

◆ text()

std::string nmodl::ModToken::text ( ) const
inline

Return token text from mod file.

Definition at line 90 of file modtoken.hpp.

◆ type()

int nmodl::ModToken::type ( ) const
inline

Return token type from lexer.

Definition at line 95 of file modtoken.hpp.

Friends And Related Function Documentation

◆ operator+

ModToken operator+ ( ModToken const &  adder1,
ModToken const &  adder2 
)
friend

Overload + operator to create an object whose position starts from the start line and column of the first adder and finishes at the end line and column of the second adder.

For example:

a at [118.9-14]
b at [121.4-5]

Output:

(a + b) at [118.9-121.5]

Definition at line 32 of file modtoken.cpp.

◆ operator<<

std::ostream& operator<< ( std::ostream &  stream,
const ModToken mt 
)
friend

Overload << operator to print object.

Overload ostream operator to print token in the form :

token at [line.start_column-end_column] type token

For example:

v at [118.9-14] type 376

Definition at line 26 of file modtoken.cpp.

Member Data Documentation

◆ external

bool nmodl::ModToken::external = false
private

true if token is externally defined variable (e.g. t, dt in NEURON)

Definition at line 64 of file modtoken.hpp.

◆ name

std::string nmodl::ModToken::name
private

name of the token

Definition at line 55 of file modtoken.hpp.

◆ pos

LocationType nmodl::ModToken::pos
private

position of token in the mod file

Definition at line 61 of file modtoken.hpp.

◆ token

int nmodl::ModToken::token = -1
private

token value returned by lexer

Definition at line 58 of file modtoken.hpp.


The documentation for this class was generated from the following files:
nmodl::ModToken::token
int token
token value returned by lexer
Definition: modtoken.hpp:58
nmodl::ModToken::type
int type() const
Return token type from lexer.
Definition: modtoken.hpp:95