User Guide
nmodl::parser::NmodlLexer Class Reference

Represent Lexer/Scanner class for NMODL language parsing. More...

Detailed Description

Represent Lexer/Scanner class for NMODL language parsing.

Lexer defined to add some extra function to the scanner class from flex. Flex itself creates yyFlexLexer class, which we renamed using macros to NmodlFlexLexer. But we change the context of the generated yylex() function because the yylex() defined in NmodlFlexLexer has no parameters. Also, note that implementation of the member functions are in nmodl.l file due to use of macros.

Definition at line 60 of file nmodl_lexer.hpp.

#include <nmodl_lexer.hpp>

Inheritance diagram for nmodl::parser::NmodlLexer:

Public Member Functions

void reset_end_position ()
 Reset the column position of lexer to 0. More...
 
virtual NmodlParser::symbol_type next_token ()
 Function for lexer to scan token (replacement for yylex()) More...
 
void scan_unit ()
 Scan subsequent text as unit. More...
 
std::string input_line ()
 Input text until end of line. More...
 
ast::Stringget_unit ()
 Return last scanned unit as ast::String. More...
 
std::string get_curr_line () const
 Return current line as string. More...
 
void set_debug (bool b)
 Enable debug output (via yyout) if compiled into the scanner. More...
 
Ctor & dtor
 NmodlLexer (NmodlDriver &driver, std::istream *in=nullptr, std::ostream *out=nullptr)
 NmodlLexer constructor. More...
 
 ~NmodlLexer () override=default
 

Public Attributes

location loc
 location of the parsed token More...
 

Private Attributes

NmodlDriverdriver
 Reference to driver object where this lexer resides. More...
 
ast::Stringlast_unit = nullptr
 Units are stored in the scanner (could be stored in the driver though) More...
 
int lexical_context = 0
 Context of the reaction (~) token. More...
 
std::string cur_line
 

Constructor & Destructor Documentation

◆ NmodlLexer()

nmodl::parser::NmodlLexer::NmodlLexer ( NmodlDriver driver,
std::istream *  in = nullptr,
std::ostream *  out = nullptr 
)
inlineexplicit

NmodlLexer constructor.

Parameters
driverNmodlDriver where this lexer resides
inInput stream from where tokens will be read
outOutput stream where output will be sent

Definition at line 98 of file nmodl_lexer.hpp.

◆ ~NmodlLexer()

nmodl::parser::NmodlLexer::~NmodlLexer ( )
overridedefault

Member Function Documentation

◆ get_curr_line()

std::string nmodl::parser::NmodlLexer::get_curr_line ( ) const

Return current line as string.

◆ get_unit()

ast::String* nmodl::parser::NmodlLexer::get_unit ( )

Return last scanned unit as ast::String.

◆ input_line()

std::string nmodl::parser::NmodlLexer::input_line ( )

Input text until end of line.

For construct like TITLE we have to scan text until end of line

◆ next_token()

virtual NmodlParser::symbol_type nmodl::parser::NmodlLexer::next_token ( )
virtual

Function for lexer to scan token (replacement for yylex())

This is main lexing function generated by flex according to the macro declaration YY_DECL. The generated bison parser then calls this virtual function to fetch new tokens. Note that yylex() has different declaration and hence can't be used for new lexer.

Returns
Symbol encapsulating parsed token

◆ reset_end_position()

void nmodl::parser::NmodlLexer::reset_end_position ( )
inline

Reset the column position of lexer to 0.

Due to COPY mode the end position is not accurate. Set column to 0 to avoid confusion (see JIRA issue NOCMODL-25)

Definition at line 114 of file nmodl_lexer.hpp.

◆ scan_unit()

void nmodl::parser::NmodlLexer::scan_unit ( )

Scan subsequent text as unit.

For units we have to consume string until end of closing parenthesis and store it in the scanner. This will be later returned by get_unit().

◆ set_debug()

void nmodl::parser::NmodlLexer::set_debug ( bool  b)

Enable debug output (via yyout) if compiled into the scanner.

Member Data Documentation

◆ cur_line

std::string nmodl::parser::NmodlLexer::cur_line
private

Definition at line 82 of file nmodl_lexer.hpp.

◆ driver

NmodlDriver& nmodl::parser::NmodlLexer::driver
private

Reference to driver object where this lexer resides.

The driver object is used for macro definitions and error checking

Definition at line 66 of file nmodl_lexer.hpp.

◆ last_unit

ast::String* nmodl::parser::NmodlLexer::last_unit = nullptr
private

Units are stored in the scanner (could be stored in the driver though)

Definition at line 69 of file nmodl_lexer.hpp.

◆ lexical_context

int nmodl::parser::NmodlLexer::lexical_context = 0
private

Context of the reaction (~) token.

For reaction (~) we return different token based on one of the following lexical context:

  • NONLINEAR
  • LINEAR
  • KINETIC

Definition at line 80 of file nmodl_lexer.hpp.

◆ loc

location nmodl::parser::NmodlLexer::loc

location of the parsed token

Definition at line 86 of file nmodl_lexer.hpp.


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