GNU   davin.50webs.com/research
Bringing to you notes for the ages

       Main Menu          Research Projects         Photo Album            Curriculum Vitae      The Greatest Artists
    Email Address       Computer Games          Web Design          Java Training Wheels      The Fly (A Story)   
  Political Activism   Scruff the Cat       My Life Story          Smoking Cessation          Other Links      
Debugging Macros     String Class I     Linked List System I Java for C Programmers Naming Convention
    String Class II         How I use m4              Strings III                 Symmetrical I/O             Linked Lists II     
Run-Time Type Info   Virtual Methods      An Array System        Science & Religion            Submodes       
  Nested Packages      Memory Leaks    Garbage Collection      Internet & Poverty      What is Knowledge?
Limits of Evolution   Emacs Additions      Function Plotter           Romantic Love        The Next Big Thing
    Science Fiction     Faster Compilation Theory of Morality         Elisp Scoping               Elisp Advice      
  S.O.G.M. Pattern       Safe Properties         School Bullying          Charisma Control          Life and Death    
     Splitting Java          Multiple Ctors       Religious Beliefs         Conversation 1           Conversation 2    
   J.T.W. Language    Emacs Additions II      Build Counter             Relation Plotter          Lisp++ Language  
  Memory Leaks II   Super Constructors CRUD Implementation Order a Website Form There Is An Afterlife
More Occam's Razor C to Java Translator Theory of Morality II


reader.hh

    
#ifndef already_included_reader_hh
#define already_included_reader_hh

class Gulper
{
public:
   virtual ~Gulper() {}
   virtual int gulp_char() = null;
};

class FileGulper : public Gulper
{
private:
   FILE* f;
   bool ours_to_close;
public:
   FileGulper(string file_name);
   FileGulper(const char* file_name);
   FileGulper(FILE* f);
   ~FileGulper();
   int gulp_char();
};

class Reader_core
{
private:
   enum Return_values {
      TT_eof = -1, TT_void=256, TT_char, TT_int, TT_double,
      TT_identifier, TT_string, TT_bool,
   };

Gulper*       reader;
   int           current;
   Return_values current_type;
   string        file_name;

public:
   Reader_core(string file_name);
   ~Reader_core();

bool currently_bool()       { return current_type == TT_bool; }
   bool currently_char()       { return current_type == TT_char; }
   bool currently_int()        { return current_type == TT_int; }
   bool currently_double()     { return current_type == TT_double; }
   bool currently_identifier() { return current_type == TT_identifier; }
   bool currently_string()     { return current_type == TT_string; }
   bool currently_eof()        { return current_type == TT_eof; }

bool   peek_bool();
   char   peek_char();
   int    peek_int();
   double peek_double();
   string peek_identifier();
   string peek_string();

void   next_token();
   int    get_file_line();
   string get_file_name();

private:
   void        skip_whitespace();
   int         scan_int();
   double      scan_fraction();
   string      scan_identifier();
   string      scan_quoted_string();
   double      fractionalise(int i);
   void        gulp();
   void        wrong_type(string tname);
   /* DIAGNOSTICS: */
   void   error(string s);
   string debug_say_symbol();

char        last_char;
   int         last_int;
   double      last_double;
   string      last_identifier;
   string      last_string;
   bool        last_bool;
   int         current_line;
   string      current_file;
};

class Reader : public Reader_core
{
public:
   Reader(string file_name) : Reader_core(file_name) {}
   /* PEEKING: */
   bool looking_at(char ch);
   bool looking_at(string s);
   /* READING LITERALS: */
   friend Reader& operator>>(Reader& r, const char& ch);
   friend Reader& operator>>(Reader& r, const char* s);
   /* GULPING DATA: */
   friend Reader& operator>>(Reader& r, bool& b);
   friend Reader& operator>>(Reader& r, char& ch);
   friend Reader& operator>>(Reader& r, int& i);
   friend Reader& operator>>(Reader& r, double& d);
   friend Reader& operator>>(Reader& r, string& s);
   string gulp_quoted_string();
};

#endif /* already_included_reader_hh */
Back
| Main Menu | Research Projects | Photo Album | Curriculum Vitae | The Greatest Artists |
| Email Address | Computer Games | Web Design | Java Training Wheels | The Fly (A Story) |
| Political Activism | Scruff the Cat | My Life Story | Smoking Cessation | Other Links |
| Debugging Macros | String Class I | Linked List System I | Java for C Programmers | Naming Convention |
| String Class II | How I use m4 | Strings III | Symmetrical I/O | Linked Lists II |
| Run-Time Type Info | Virtual Methods | An Array System | Science & Religion | Submodes |
| Nested Packages | Memory Leaks | Garbage Collection | Internet & Poverty | What is Knowledge? |
| Limits of Evolution | Emacs Additions | Function Plotter | Romantic Love | The Next Big Thing |
| Science Fiction | Faster Compilation | Theory of Morality | Elisp Scoping | Elisp Advice |
| S.O.G.M. Pattern | Safe Properties | School Bullying | Charisma Control | Life and Death |
| Splitting Java | Multiple Ctors | Religious Beliefs | Conversation 1 | Conversation 2 |
| J.T.W. Language | Emacs Additions II | Build Counter | Relation Plotter | Lisp++ Language |
| Memory Leaks II | Super Constructors | CRUD Implementation | Order a Website Form | There Is An Afterlife |
| More Occam's Razor | C to Java Translator | Theory of Morality II
Last modified: Sun Sep 25 16:08:48 NZDT 2016
Best viewed at 800x600 or above resolution.
© Copyright 1999-2016 Davin Pearson.
Please report any broken links to