Click here to Skip to main content
12,357,875 members (72,565 online)
Click here to Skip to main content

Stats

149.9K views
2.6K downloads
54 bookmarked
Posted

Tokenizer and analyzer package supporting precedence prioritized rules

, 1 Jan 2002
A library allowing you to conveniently build a custom tokenizer and analyzer supporting precedence priorized rules
cxTokenizer
cxTokenizer.dsp
cxTokenizer.plg
cxtPackage
cxtPackage.plg
cxtPackage.dsp
mathTok
mathTok.plg
mathTok.dsp
simpleCalc
simpleCalc.bmp
simpleCalc.dsp
simpleCalc.plg
tkCommon
cxAnalyzer
cxAnalyzer.dsp
cxAnalyzer.plg
COPYING
cpAbsd.dsw
cxTokenizer.dsp
cxTokenizer.plg
Debug
cxAnalyzer.dsp
cxAnalyzer.plg
cxtPackage.plg
cxtPackage.dsp
COPYING
cpAbsd.dsw
stlport_vc645.dll
grammarIDE.exe
cxTokenizerMatchTokenRule.inl
cxTokenizer.dsp
cxtPackage.dsp
emptyTestApp
emptyTestApp.clw
res
emptyTestApp.ico
emptyTestApp.dsp
grammarIDE
grammarIDE.clw
res
grammarIDEDoc.ico
icon1.ico
zoomable.ico
Toolbar.bmp
grammarIDE.ico
vssver.scc
grammarIDE.dsp
simpleCalc.bmp
simpleCalc.dsp
vssver.scc
cxaToken.inl
cxAnalyzer.dsp
COPYING
cpAbsd.dsw
cxTokenizerMatchTokenRule.inl
cxTokenizer.dsp
cxtPackage.dsp
emptyTestApp.clw
emptyTestApp.ico
emptyTestApp.dsp
vssver.scc
cxaToken.inl
cxAnalyzer.dsp
COPYING
cpAbsd.dsw
// 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.

License

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

Share

About the Author

Alexander Berthold
Web Developer
Germany Germany
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 2 Jan 2002
Article Copyright 2001 by Alexander Berthold
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid