FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
lex.bi
Go to the documentation of this file.
1
''
2
'' lex protos
3
''
4
5
#include once
"
dstr.bi
"
6
7
enum
LEXCHECK
8
9
LEXCHECK_EVERYTHING
= &h0000
10
11
'' ? write this comment
12
LEXCHECK_NOLINECONT
= &h0001
13
14
'' don't replace define/macro text
15
LEXCHECK_NODEFINE
= &h0002
16
17
'' return CHAR_SPACE, CHAR_TAB... (usually skipped when lexing)
18
LEXCHECK_NOWHITESPC
= &h0004
19
20
'' don't interpret $, #, &, etc as a suffix on a token (for #include, $include, &h1, more?)
21
LEXCHECK_NOSUFFIX
= &h0008
22
23
'' retain quotes in any literal string's token (otherwise, hReadString removes quotes so lexGetText can cleanly return the string's content)
24
LEXCHECK_NOQUOTES
= &h0010
25
26
'' don't associate the token with a symbol chain (dim shared as integer foo: #define bar(foo)
27
LEXCHECK_NOSYMBOL
= &h0020
28
29
'' return CHAR_DOT (usually incorporated into whatever symbol when lexing)
30
LEXCHECK_NOPERIOD
= &h0040
31
32
'' used to handle the 'periods in symbol name' garbage
33
LEXCHECK_EATPERIOD
= &h0080
34
35
'' use the special symbol 'namespace' for pre-processing, to prevent polluting the global ns
36
LEXCHECK_KWDNAMESPC
= &h0100
37
38
'' ignore multi-line comment markers in code (don't allow them in single-line comments)
39
LEXCHECK_NOMULTILINECOMMENT
= &h0200
40
41
'' don't interpret f, u, l as type-specifier suffixes on numeric literals (used in asm blocks)
42
LEXCHECK_NOLETTERSUFFIX
= &h0400
43
44
end enum
45
46
type
FBTOKEN
47
id
as integer
48
class
as integer
49
dtype
as integer
50
51
'' used by literal strings too
52
union
53
text
as zstring
* FB_MAXLITLEN+1
54
textw
as wstring
* FB_MAXLITLEN+1
55
end union
56
57
len
as integer
'' length
58
sym_chain
as
FBSYMCHAIN
ptr
'' symbol found, if any
59
60
union
61
prdpos
as integer
'' period '.' pos in symbol names
62
hasesc
as integer
'' any '\' in literals
63
end union
64
65
after_space
as integer
66
67
next
as
FBTOKEN
ptr
68
end type
69
70
const
FB_LEX_MAXK
= 3
71
72
const
LEX_MAXBUFFCHARS
= 8192
73
74
type
LEX_TKCTX
75
tokenTB
(0
to
FB_LEX_MAXK
)
as
FBTOKEN
76
k
as integer
'' look ahead cnt (1..MAXK)
77
78
head
as
FBTOKEN
ptr
79
tail
as
FBTOKEN
ptr
80
81
currchar
as uinteger
'' current char
82
lahdchar
as uinteger
'' look ahead char
83
84
linenum
as integer
85
lasttk_id
as integer
86
87
reclevel
as integer
'' PP recursion
88
currmacro
as
FBSYMBOL
ptr
'' used to check macro recursion
89
90
kwdns
as
FBSYMBOL
ptr
'' used by the PP
91
92
'' last #define's text
93
deflen
as integer
94
95
union
96
type
97
defptr
as zstring ptr
98
deftext
as
DZSTRING
99
end type
100
101
type
102
defptrw
as wstring ptr
103
deftextw
as
DWSTRING
104
end type
105
end union
106
107
'' input buffer
108
bufflen
as integer
109
110
union
111
type
112
buffptr
as zstring ptr
113
buff
as zstring
*
LEX_MAXBUFFCHARS
+1
114
end type
115
116
type
117
buffptrw
as wstring ptr
118
buffw
as wstring
*
LEX_MAXBUFFCHARS
+1
119
end type
120
end union
121
122
filepos
as integer
123
lastfilepos
as integer
124
125
currline
as
DZSTRING
'' current line in text form
126
127
after_space
as integer
128
end type
129
130
type
LEX_CTX
131
ctxTB
( 0
TO
FB_MAXINCRECLEVEL-0 )
as
LEX_TKCTX
132
ctx
as
LEX_TKCTX
ptr
133
134
insidemacro
as integer
135
end type
136
137
declare sub
lexInit
_
138
( _
139
byval
isinclude
as integer
_
140
)
141
142
declare sub
lexEnd
_
143
( _
144
)
145
146
declare sub
lexPushCtx
_
147
( _
148
)
149
150
declare sub
lexPopCtx
_
151
( _
152
)
153
154
declare function
lexGetToken
_
155
( _
156
byval
flags
as
LEXCHECK
=
LEXCHECK_EVERYTHING
_
157
)
as integer
158
159
declare function
lexGetClass
_
160
( _
161
byval
flags
as
LEXCHECK
=
LEXCHECK_EVERYTHING
_
162
)
as integer
163
164
declare function
lexGetText
_
165
( _
166
)
as zstring ptr
167
168
declare sub
lexEatToken
_
169
( _
170
byval
token
as zstring ptr
, _
171
byval
flags
as
LEXCHECK
=
LEXCHECK_EVERYTHING
_
172
)
173
174
declare sub
lexPPOnlyEmitToken
( )
175
declare sub
lexPPOnlyEmitText
(
byref
s
as string
)
176
declare sub
lexSkipToken
(
byval
flags
as
LEXCHECK
=
LEXCHECK_EVERYTHING
)
177
178
declare function
lexGetLookAheadClass
_
179
( _
180
byval
k
as integer
, _
181
byval
flags
as
LEXCHECK
=
LEXCHECK_EVERYTHING
_
182
)
as integer
183
184
declare function
lexGetLookAhead
_
185
( _
186
byval
k
as integer
, _
187
byval
flags
as
LEXCHECK
=
LEXCHECK_EVERYTHING
_
188
)
as integer
189
190
declare sub
lexReadLine
_
191
( _
192
byval
endchar
as uinteger
=
INVALID
, _
193
byval
dst
as zstring ptr
, _
194
byval
skipline
as integer
=
FALSE
_
195
)
196
197
declare sub
lexSkipLine
_
198
( _
199
)
200
201
declare sub
lexNextToken
_
202
( _
203
byval
t
as
FBTOKEN
ptr
, _
204
byval
flags
as
LEXCHECK
=
LEXCHECK_EVERYTHING
_
205
)
206
207
declare function
lexCurrentChar
_
208
( _
209
byval
skipwhitespc
as integer
=
FALSE
_
210
)
as uinteger
211
212
declare function
lexGetLookAheadChar
_
213
( _
214
byval
skipwhitespc
as integer
=
FALSE
_
215
)
as uinteger
216
217
declare function
lexEatChar
_
218
( _
219
)
as uinteger
220
221
declare function
lexPeekCurrentLine
_
222
( _
223
byref
token_pos
as string
, _
224
byval
do_trim
as integer
_
225
)
as string
226
227
228
''
229
'' macros
230
''
231
232
#define
lexLineNum( )
lex
.
ctx
->
linenum
233
234
#define
lexGetLastToken( )
lex
.
ctx
->
lasttk_id
235
236
#define
lexGetTextW( ) @
lex
.
ctx
->
head
->
textw
237
238
#define
lexGetTextLen( )
lex
.
ctx
->
head
->
len
239
240
#define
lexGetType( )
lex
.
ctx
->
head
->
dtype
241
242
#define
lexGetSymChain( )
lex
.
ctx
->
head
->
sym_chain
243
244
#define
lexGetPeriodPos( )
lex
.
ctx
->
head
->
prdpos
245
246
#define
lexGetHasSlash( )
lex
.
ctx
->
head
->
hasesc
247
248
#define
lexGetHead( )
lex
.
ctx
->
head
249
250
#define
lexCurrLineGet( )
lex
.
ctx
->
currline
.
data
251
252
#define
lexCurrLineReset( ) DZstrReset(
lex
.
ctx
->
currline
)
253
254
''
255
'' inter-module globals
256
''
257
extern
lex
as
LEX_CTX
258
259
260
261
compiler
lex.bi
Generated on Thu Jan 23 2014 19:39:33 for FreeBASIC by
1.8.4