NEST  2.6.0,not_revisioned_source_dir@0
scanner.h
Go to the documentation of this file.
1 /*
2  * scanner.h
3  *
4  * This file is part of NEST.
5  *
6  * Copyright (C) 2004 The NEST Initiative
7  *
8  * NEST 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  * NEST 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 NEST. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 # ifndef Scanner_H
24 #define Scanner_H
25 /*
26  SLI's lexical analyzer
27 
28 */
29 #include <typeinfo>
30 #include <iostream>
31 #include <string>
32 
33 #include "token.h"
34 #include "symboldatum.h"
35 #include "charcode.h"
36 
37 
38 class Scanner
39 {
40  std::istream* in;
41 
42  CharCode code; // some Chars cause the same Transition
43 
44  unsigned long line;
45  unsigned long col;
46  std::string context;
47  std::string old_context;
48  enum ScanStates {
49  start=0,
91  end,
95  };
96 
97  enum Codes {
123  };
124 
125  enum ScanStates trans[lastscanstate][lastcode]; // DFA transition-function
126 
127 
128 
129 
130  const unsigned char space;
131  const unsigned char tab;
132  const unsigned char endoln;
133  const unsigned char cr; // carriage return (ctrl M)
134  const unsigned char endof;
135  int digval(unsigned char c) const
136  {return c-'0';}
137 
138 
139 
140 public:
146 
150  Scanner(std::istream *);
151 
155  void source(std::istream *);
156 
160  std::istream* GetSource(void) {return in; }
161 
165  bool operator()(Token&);
166 
170  void print_error(const char *);
171 
175  unsigned long get_line() const
176  {
177  return line;
178  }
179 
183  unsigned long get_col() const
184  {
185  return col;
186  }
187 
189  {
190  line=0;
191  col=0;
192  context.clear();
193  old_context.clear();
194  }
195 };
196 
197 # endif
198 
199 
Codes
Definition: scanner.h:97
Definition: scanner.h:99
Definition: scanner.h:107
Definition: scanner.h:84
Definition: scanner.h:53
Definition: scanner.h:83
SymbolDatum BeginProcedureSymbol
Definition: scanner.h:143
Definition: scanner.h:101
std::string context
Current context.
Definition: scanner.h:46
Definition: scanner.h:60
Definition: scanner.h:109
std::istream * GetSource(void)
Return input stream.
Definition: scanner.h:160
std::string old_context
Definition: scanner.h:47
Scanner(std::istream *)
Initialise scanner with a stream.
Definition: scanner.cc:89
Definition: scanner.h:104
Definition: scanner.h:74
Definition: scanner.h:54
Definition: scanner.h:49
Definition: scanner.h:76
const unsigned char tab
Definition: scanner.h:131
Definition: scanner.h:81
Definition: scanner.h:62
unsigned long line
Current line number.
Definition: scanner.h:44
Definition: scanner.h:56
Definition: scanner.h:110
Definition: scanner.h:85
Definition: scanner.h:71
Definition: scanner.h:105
void source(std::istream *)
Set new input stream.
Definition: scanner.cc:492
Definition: scanner.h:108
Definition: scanner.h:86
Definition: scanner.h:55
Definition: scanner.h:52
bool operator()(Token &)
Scan input until the next Token.
Definition: scanner.cc:505
Definition: scanner.h:70
unsigned long get_col() const
Return position in current line in input stream.
Definition: scanner.h:183
void clear_context()
Definition: scanner.h:188
int digval(unsigned char c) const
Definition: scanner.h:135
Definition: scanner.h:67
Definition: scanner.h:59
Definition: scanner.h:51
Definition: scanner.h:106
Definition: scanner.h:80
Definition: scanner.h:79
Definition: scanner.h:115
const unsigned char endof
Definition: scanner.h:134
Definition: scanner.h:92
Definition: scanner.h:94
Definition: scanner.h:72
SymbolDatum EndProcedureSymbol
Definition: scanner.h:144
Definition: scanner.h:93
Definition: scanner.h:87
Definition: scanner.h:38
Definition: scanner.h:118
Definition: scanner.h:61
const unsigned char cr
Definition: scanner.h:133
Definition: scanner.h:68
SymbolDatum EndArraySymbol
Definition: scanner.h:142
Definition: scanner.h:113
CharCode code
Definition: scanner.h:42
Definition: charcode.h:39
Definition: scanner.h:121
const unsigned char endoln
Definition: scanner.h:132
Definition: scanner.h:75
Definition: scanner.h:69
Definition: scanner.h:111
Definition: scanner.h:100
Definition: scanner.h:119
Definition: scanner.h:66
Definition: scanner.h:64
Definition: scanner.h:90
Definition: scanner.h:57
Definition: scanner.h:103
Definition: scanner.h:63
Definition: scanner.h:78
Definition: scanner.h:58
std::istream * in
Definition: scanner.h:40
Definition: scanner.h:77
Definition: scanner.h:116
Definition: scanner.h:102
ScanStates
Definition: scanner.h:48
Definition: scanner.h:114
Definition: scanner.h:50
Definition: symboldatum.h:51
Definition: scanner.h:89
Definition: scanner.h:98
void print_error(const char *)
Issue an error message.
Definition: scanner.cc:783
Definition: scanner.h:88
SymbolDatum BeginArraySymbol
Definition: scanner.h:141
A type-independent container for C++-types.
Definition: token.h:68
unsigned long get_line() const
Return current line number in input stream.
Definition: scanner.h:175
Definition: scanner.h:82
Definition: scanner.h:122
Definition: scanner.h:120
const Name c("c")
Specific to Izhikevich 2003.
Definition: nest_names.h:62
SymbolDatum EndSymbol
Definition: scanner.h:145
Definition: scanner.h:73
const unsigned char space
Definition: scanner.h:130
Definition: scanner.h:65
Definition: scanner.h:91
unsigned long col
Current column in line.
Definition: scanner.h:45
Definition: scanner.h:112
enum ScanStates trans[lastscanstate][lastcode]
Definition: scanner.h:125
Definition: scanner.h:117