16namespace layer1_foundations {
17namespace expression_parser {
61 else if (t ==
MINUS) {
79 else if (t ==
COMMA) {
110 s.assign(
"ASSIGN_ADD");
113 s.assign(
"ASSIGN_SUB");
116 s.assign(
"ASSIGN_MUL");
119 s.assign(
"ASSIGN_DIV");
126 int f_v = (verbose_level >= 1);
129 word_.erase (0, std::string::npos);
140 throw std::runtime_error (
"Unexpected end of expression.");
142 unsigned char cFirstCharacter = *
pWord_;
144 if (cFirstCharacter == 0)
146 word_ =
"<end of expression>";
148 std::cout <<
"token END " <<
word_ << std::endl;
154 unsigned char cNextCharacter = *(
pWord_ + 1);
162 (cFirstCharacter ==
'+' || cFirstCharacter ==
'-') &&
163 (isdigit (cNextCharacter) || cNextCharacter ==
'.')
165 || isdigit (cFirstCharacter)
168 || (cFirstCharacter ==
'.' && isdigit (cNextCharacter)) )
171 if ((cFirstCharacter ==
'+' || cFirstCharacter ==
'-'))
188 std::istringstream is (
word_);
192 if (is.fail () && !is.eof ())
193 throw std::runtime_error (
"Bad numeric literal: " +
word_);
195 std::cout <<
"token NUMBER " <<
value_ << std::endl;
204 if (cNextCharacter ==
'=')
206 switch (cFirstCharacter)
227 std::cout <<
"token operator ";
229 std::cout << std::endl;
236 switch (cFirstCharacter)
238 case '&':
if (cNextCharacter ==
'&')
243 std::cout <<
"token AND " << std::endl;
251 case '|':
if (cNextCharacter ==
'|')
256 std::cout <<
"token OR " << std::endl;
280 std::cout <<
"token operator ";
282 std::cout << std::endl;
289 if (!isalpha (cFirstCharacter))
291 if (cFirstCharacter <
' ')
293 std::ostringstream s;
294 s <<
"Unexpected character (decimal " << int (cFirstCharacter) <<
")";
295 throw std::runtime_error (s.str ());
298 throw std::runtime_error (
"Unexpected character: " + std::string (1, cFirstCharacter));
308 std::cout <<
"token NAME " <<
word_ << std::endl;
345 std::ostringstream s;
346 s <<
"'" <<
static_cast <char> (wanted) <<
"' expected.";
347 throw std::runtime_error (s.str ());
void CheckToken(TokenType wanted)
TokenType GetToken(int verbose_level, const bool ignoreSign=false)
void print_token(std::ostream &ost, TokenType t)
void token_as_string(std::string &s, TokenType t)
void create_text_token(std::string &txt)
syntax_tree_node_terminal * T
void create_double_token(double dbl)
terminal note in the syntax tree of an expression
the orbiter library for the classification of combinatorial objects