Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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
cxtpackagetut_win32vc.zip
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
cxtpackage_win32vc.zip
cxTokenizer.dsp
cxTokenizer.plg
Debug
cxAnalyzer.dsp
cxAnalyzer.plg
cxtPackage.plg
cxtPackage.dsp
COPYING
cpAbsd.dsw
grammaride.zip
stlport_vc645.dll
grammarIDE.exe
pkgcomplete.zip
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
pkgsrconly.zip
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

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 2 Jan 2002
Article Copyright 2001 by Alexander Berthold
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid