1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
#ifndef LEX_HPP
#define LEX_HPP

#include <iostream>
#include "token.hpp"

namespace LambdaCalc {

   class Lex {
      public:
  Lexsp;  Lex(std::istream& in, std::ostream& out,
        const std::string& prompt1, const std::string& prompt2);

     // accessors
     bovalidpan> valid() const;
        /* check if this lex object continues to read from
           its input. Once this returns false, the return
           value remains false fur all further invocations */

     // mutators
     vomarkFinishedsp;markFinished();
        /* tell the lexical analyser that a complete
           expression has been read. This information is used
           to print the correct prompt. */
  Token;  TokgetTokenken();
        /* read and return the next token from the input.
           Note however that no further read operations are
           performed once an error or end of file has been
           found. */

     // istream-like behaviour
     operator bool() const;
  Lexsp;  Lex& operatorTokengt;(Token& token);

      private:
     std::istream& in; // input stream
     std::ostream& out; // used for prompts
     const std::string prompt1; // at the beginning of an expression
     const std::string prompt2; // in the middle of an expression
     bool eof; // eof detected? this flag is sticky!
     bool error; // error detected? this is sticky as well
     char ch; // current character read
     bool start; // at the beginning of a line?
     bool finished; // was one expression finished?

     vonextspan> next();
   };

// namespace LambdaCalc

#endif