[Bio] / smc / stContext.py Repository:
ViewVC logotype

View of /smc/stContext.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Fri Sep 26 19:36:17 2003 UTC (16 years, 1 month ago) by park
Branch: MAIN
CVS Tags: HEAD
Extend to generate Python statemachines.
   o  smc  < foo.sm   makes c++
   o  smc -c < foo.sm makes c++
   o  smc -p < foo.sm makes python

The yacc is written (originally) to call GenStateMap when the
end of the document is hit.  We make GenStateMap call
generator which is a ptr to function.  We set the fn
to call in main via command line opts.

#!/usr/bin/python

#----------------------------------------------------------

#    stContext Header file

#

#     This is the context class of the comment stripper.

#     This class knows about the input and output streams,

#     How to read and write chars, and which critical chars to

#      look for in the input stream.

#

#         python version of stripper.cc

#          September, 2003

#-----------------------------------------------------------


import sys
import string


class StripperContext:

    def __init__(self):

	self.itsChar = ""
	self.itsIStream = ""
	self.itsOStream = ""

    def SetStreams(self, i, o):
        self.itsIStream = i
        self.itsOStream = o
        return

    def FSMError(self,  t, s):
        print "Transition error: %s in state %s" % (t, s)
        return
    
    
    def ReadChar(self ):
        self.itsChar =  self.itsIStream.read(1)
        return self.itsChar

    
    def PutChar(self):
        
        self.itsOStream.write(self.itsChar)
        return 
    
    def PutSlash(self):
        
        self.itsOStream.write('/')
        return 


#endif



"""
#ifndef _H_stripperContext
#define _H_stripperContext

// $Id: stContext.py,v 1.1 2003/09/26 19:36:17 park Exp $
#include <iostream.h>

//
// This is the context class of the comment stripper.
// This class knows about the input and output streams,
// How to read and write chars, and which critical chars to
// look for in the input stream.
//

class StripperContext
{
private:
	char itsChar;
	istream *itsIStream;
	ostream *itsOStream;

public:
	StripperContext() { }

    void SetStreams(istream& i, ostream& o)
    {
      itsIStream = &i;
      itsOStream = &o;
    }

    void FSMError(const char* t, const char* s)
    {cerr << "Transition error: " << t << " in state " << s << endl;}

	int ReadChar()
	{
	  int c;
	  c = itsIStream->get();
	  itsChar = c;
	  return c;
	}
	void PutChar() {*itsOStream << itsChar;};
	void PutSlash() {*itsOStream << '/';};
};

#endif
"""

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3