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

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.