|
// mathTok.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
class cTestListener :
public cxTokenizerListener
{
// Operations
public:
virtual bool fCheckValid() const { return true; };
virtual bool fShouldDelete() const { return false; };
virtual void vRegisterToken(const std::tstring& strTokenText,
const cxTokenizerTokenRule* pttrRule,
const cxTokenizerInputStream* ptisStream)
{
if(pttrRule!=NULL)
{
std::cout << "token(" << pttrRule->nGetIDValue() << "): ";
std::cout << strTokenText << std::endl;
}
else
{
std::cout << "NULL token: " << strTokenText << std::endl;
}
};
};
int main(int argc, char* argv[])
{
std::tstringstream setup(
"[tokens]\n"
"100:sin\n" "101:cos\n"
"102:tan\n" "103:sqrt\n"
"[seperators]\n"
"200:+\n" "201:-\n"
"202:*\n" "203:/\n"
"204:(\n" "205:)\n"
"[rules]\n"
"300:numbers\n"
);
// Let the user enter the string to tokenize
TCHAR szUserData[256];
std::cout << "Enter a string to tokenize: ";
std::cin.getline(szUserData,256);
// 'setup': see previous slide
cxTokenizerMap tmap(setup);
// Build a cxTokenizer - compatible input stream
cxTokenizerTextInputStream<cxTokenizerInputStreamDefaultImpl<crlf_cronly> > tistream(szUserData);
// Create an instance of our listener class
cTestListener tlis;
cxTokenizer tokenizer(&tistream,&tmap,&tlis);
while(!tistream.fIsEofReached())
tokenizer.vParseCharacter();
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.