]> www.ginac.de Git - ginac.git/blob - ginac/parser/lexer.h
7d23c091cf3bb39a16103460e751a760dfa18390
[ginac.git] / ginac / parser / lexer.h
1 /** @file lexer.h
2  *
3  *  The lexer. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2009 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef GINAC_LEXER_H
24 #define GINAC_LEXER_H
25
26 #include <iosfwd>
27 #include <string>
28 #include <cstddef>
29
30 namespace GiNaC {
31
32 class lexer
33 {
34         std::istream* input;
35         std::ostream* output;
36         std::ostream* error;
37         /// last character read from stream
38         int c;
39         /// identifier and number tokens are stored here
40         std::string str;
41         std::size_t line_num;
42         std::size_t column;
43         friend class parser;
44 public:
45
46         lexer(std::istream* in = 0, std::ostream* out = 0, std::ostream* err = 0);
47         ~lexer();
48
49         int gettok();
50         void switch_input(std::istream* in);
51
52         struct token_type
53         {
54                 enum
55                 {
56                         eof             = -1,
57                         identifier      = -4,
58                         number          = -5,
59                         literal         = -6
60
61                 };
62         };
63         
64         /// Symbolic name of the token (for error reporting)
65         std::string tok2str(const int tok) const;
66 };
67
68 } // namespace GiNaC
69
70 #endif // ndef GINAC_LEXER_H