The C++ Lexer Toolkit Library (LexerTk) is a simple to use, easy to
integrate and extremely fast lexicographical generator - lexer.
The tokens generated by the lexer can be used as input to a parser such
as "ExprTk".
The following example will take a string representing an expression,
tokenize it using the generator and then proceed to dump each of the
tokens to stdout, providing information related to the token such as
its type, value and position within the expression.
int main()
{
std::string expression = "(1.1 + ( x - y * z / 1.23E+4 ) % w";
lexertk::generator generator;
if (!generator.process(expression))
{
std::cout << "Failed to lex: " << expression << std::endl;
return 1;
}
lexertk::helper::dump(generator);
return 0;
}
The following example will take a string representing an expression,
tokenize it using the generator. The tokens are then analyized in
consequtive pairs. When a pair of tokens are determined to have an
implied multiplication between themselves, a token of type multiplication
is inserted between them. For example the expression '2x+1' becomes '2*x+1'.
The following example will take a string representing an expression,
tokenize it using the generator, then attempt to verify that the
ordering of the brackets within the expression is correct.