UnitStringLexer.h
1 /* Distributed under the Apache License, Version 2.0.
2  See accompanying NOTICE file for details.*/
3 
4 //----------------------------------------------------------------------------
10 //----------------------------------------------------------------------------
11 #pragma once
12 
13 // Note: See top of CompoundUnit.h for a discussion of the lines below which export STL
14 // container instantiations. In this particular case, the compiler complains about the member
15 // variables "end" and "cursor". Note that exporting the iterator base must be done before
16 // exporting the iterator template itself.
17 #pragma warning(disable:4231)
18 
19 
21 {
23  :tokenID(TT_ERR), symbol(), fltval(0.0)
24  {
25  }
27  :tokenID(src.tokenID), symbol(src.symbol), fltval(src.fltval)
28  {
29  }
30  std::string toString() const
31  {
32  switch (tokenID)
33  {
34  case TT_IDENTIFIER:
35  return "TT_IDENTIFIER";
36  break;
37 
38  case TT_EXPONENT:
39  return "TT_EXPONENT";
40  break;
41 
42  case TT_FLOAT:
43  return "TT_FLOAT";
44  break;
45 
46  case TT_SLASH:
47  return "TT_SLASH";
48  break;
49 
50  case TT_PARENOPEN:
51  return "TT_PARENOPEN";
52  break;
53 
54  case TT_PARENCLOSE:
55  return "TT_PARENCLOSE";
56  break;
57 
58  case TT_ERR:
59  return "TT_ERR";
60  break;
61 
62  case TT_EOF:
63  return "TT_EOF";
64  break;
65 
66  default:
67  return "UNDEFINED";
68 
69  } // switch
70  } // toString
71 
72  // Enumerate the various Token Types
74  std::string symbol;
75  double fltval;
76 };
77 
79 {
80 public:
81  CUnitStringLexer(const std::string &src)
82  :source(src), scanNext(true), end(source.end()), cursor(source.begin())
83  {
84  // Nothing else to do
85  }
86 
88  {
89  if (scanNext)
90  {
91  ScanNextToken();
92  }
93  token = curToken;
94  scanNext = true;
95  }
96 
98  {
99  if (scanNext)
100  {
101  ScanNextToken();
102  }
103  token = curToken;
104  scanNext = false;
105  }
106 
107 protected:
108  void ScanNextToken();
109 private:
111 
112  std::string source;
114  bool scanNext; // Determines whether a call to PeekNextToken or GetNextToken needs to scan
115  std::string::iterator end;
116  std::string::iterator cursor; // current position in source string
117 };
void PeekNextToken(SUnitStringToken &token)
Definition: UnitStringLexer.h:97
enum SUnitStringToken::@0 tokenID
std::string symbol
Definition: UnitStringLexer.h:74
CUnitStringLexer(const std::string &src)
Definition: UnitStringLexer.h:81
Definition: UnitStringLexer.h:73
std::string toString() const
Definition: UnitStringLexer.h:30
Definition: UnitStringLexer.h:78
Definition: UnitStringLexer.h:73
std::string::iterator cursor
Definition: UnitStringLexer.h:116
Definition: UnitStringLexer.h:73
void GetNextToken(SUnitStringToken &token)
Definition: UnitStringLexer.h:87
bool scanNext
Definition: UnitStringLexer.h:114
double fltval
Definition: UnitStringLexer.h:75
std::string source
Definition: UnitStringLexer.h:112
Definition: UnitStringLexer.h:73
std::string::iterator end
Definition: UnitStringLexer.h:115
Definition: UnitStringLexer.h:73
Definition: UnitStringLexer.h:73
SUnitStringToken curToken
Definition: UnitStringLexer.h:113
SUnitStringToken(SUnitStringToken &src)
Definition: UnitStringLexer.h:26
Definition: UnitStringLexer.h:73
SUnitStringToken()
Definition: UnitStringLexer.h:22
Definition: UnitStringLexer.h:20
Definition: UnitStringLexer.h:73
Definition: UnitStringLexer.h:73