/
scanner.h
157 lines (126 loc) · 4.81 KB
/
scanner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
IL : Intlog Language
Object Oriented Prolog Project
Copyright (C) 1992-2021 - Ing. Capelli Carlo
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef SCANNER_H_
#define SCANNER_H_
#include "iafx.h"
#include "srcpos.h"
#include "kstr.h"
#include <iostream>
class IntlogParser;
//-----------------------
// Intlog tokens scanner
//
class IAFX_API IntlogScanner {
public:
IntlogScanner(int);
virtual ~IntlogScanner();
void SetSource(istream *data, kstring fileId = kstring());
operator SourcePos() const;
enum Codes {
ATOM_N = 256, // atom 'normal'
ATOM_S, // signed
ATOM_Q, // quoted
INTEGER, // integer numeric sequence
INTHEX, // hexadecimal numeric sequence
DOUBLE, // numeric sequence floating point
VAR_N, // symbol variable
VAR_A, // anonym variable
STRING, // sequence of characters
POINT, // a single '.'
EOSTREAM, // end of stream
// blanks, never returned by Next
MCOMM_BEGIN, // begin multi line comment
MCOMM_LINE, // line, followed by \n
MCOMM_END, // end multi line comment
SCOMM_LINE, // a comment line, followed by \n
BLANKS, // spaces, tabs, \n
FENCE = '!',
OPEN_SQ = '[',
};
Codes Next();
// current token properties
const char* Image() const;
int Len() const;
int Row() const;
int Col() const;
// display error message in standard format
void ErrMsg(int, int = 0) const;
const char* Name() const;
// enable to sense if some input read between operations
void tokenFix();
int tokenChanged() const;
// compute current buffer value
long GetHexNum() const;
// get atom correcting for '.,.,.'
kstring GetAtom(Codes toktype);
// enable full 8 bit range processing
typedef unsigned char ch_t;
typedef unsigned char* pcch_t;
protected:
friend class IntlogParser;
istream* i; // input stream
kstring id; // file name
int clc; // current lookahead character
int rowcnt; // actual stream row counter
int colcnt; // actual stream column counter
int rowtok; // last token row counter
int coltok; // last token column counter
char* buftok; // current token image
int buflen; // current token lenght
int bufmax; // max buffer lenght
int overflow; // flag for buffer overflow
int somechange; // flag for external control on changed data
// character classification
static ch_t chclass[256];
enum {
SymBody = 0x01,
SymHead = 0x02,
VarHead = 0x04,
Sign = 0x08,
Digit = 0x10,
DigitH = 0x20,
Blank = 0x40,
Ascii = 0x80
};
static void initchclass();
static void initchstr(pcch_t, int);
static void initchset(ch_t from, ch_t to, int bit);
static int issign(ch_t); // true for sign chars
static int issymbody(ch_t); // true for symbols body chars
static int issymhead(ch_t); // true for first symbol char
static int isvarhead(ch_t); // true for first symbol variable
static int isnumber(ch_t); // true for digits
static int isnumberh(ch_t); // true for hexadecimal digits
static int isblank(ch_t); // true for blanks
static int isused(ch_t); // character has some class
int get(); // advance lookahead character in stream
void addchar(); // add a char to current token image
void backc(int); // insert char back in stream
void clear(); // reset after last token used
void nl(); // a nl in source: change line counter...
Codes retc(Codes); // fixup buffer and return to caller
void comment(); // scan one line comment
void C_comment(); // scan a C comment
void ident(); // scan a prolog identifier
Codes number(); // scan a number
// scan a sequence embedded as string
Codes seq(Codes, int);
// enable formatting...
virtual void useInput(Codes /*c*/){}
bool m_bTranslateAnsiSeq;
};
#endif