/
lex.bas
2633 lines (2147 loc) · 53.2 KB
/
lex.bas
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'' lexical scanner
''
''
'' chng: sep/2004 written [v1ctor]
'' nov/2005 unicode support added [v1ctor]
#include once "fb.bi"
#include once "fbint.bi"
#include once "lex.bi"
#include once "pp.bi"
#include once "parser.bi"
declare sub lexReadUTF8 ( )
declare sub lexReadUTF16LE ( )
declare sub lexReadUTF16BE ( )
declare sub lexReadUTF32LE ( )
declare sub lexReadUTF32BE ( )
declare sub hMultiLineComment ( )
declare sub hSkipChar( )
const UINVALID as uinteger = cuint( INVALID )
dim shared as LEX_CTX lex
'' Buffer holding the current line when emitting in -pp only mode
dim shared as string pponly_ln
'':::::
'' only update the line count if not inside a multi-line macro
#define UPDATE_LINENUM( ) _
if( lex.ctx->deflen = 0 ) then :_
lex.ctx->linenum += 1 :_
end if
'':::::
sub lexPushCtx( )
lex.ctx += 1
end sub
'':::::
sub lexPopCtx( )
if( env.includerec = 0 ) then
DZstrAllocate( lex.ctx->currline, 0 )
end if
'' free dynamic strings used in macro expansions
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
DZstrAllocate( lex.ctx->deftext, 0 )
else
DWstrAllocate( lex.ctx->deftextw, 0 )
end if
lex.ctx -= 1
end sub
'':::::
sub lexInit _
( _
byval isinclude as integer, _
byval is_fb_eval as integer _
)
dim as integer i
dim as FBTOKEN ptr n
if( (env.includerec = 0) and (is_fb_eval = FALSE) ) then
lex.ctx = @lex.ctxTB(0)
end if
'' create a circular list
lex.ctx->k = 0
lex.ctx->head = @lex.ctx->tokenTB(0)
lex.ctx->tail = lex.ctx->head
n = lex.ctx->head
for i = 0 to FB_LEX_MAXK-1
n->next = @lex.ctx->tokenTB(i+1)
n = n->next
next
n->next = lex.ctx->head
''
for i = 0 to FB_LEX_MAXK
lex.ctx->tokenTB(i).id = INVALID
next
lex.ctx->currchar = UINVALID
lex.ctx->lahdchar1 = UINVALID
lex.ctx->lahdchar2 = UINVALID
lex.ctx->is_fb_eval = is_fb_eval
if( is_fb_eval ) then
lex.ctx->linenum = (lex.ctx-1)->linenum
lex.ctx->reclevel = (lex.ctx-1)->reclevel
lex.ctx->currmacro = (lex.ctx-1)->currmacro
else
lex.ctx->linenum = 1
lex.ctx->reclevel = 0
lex.ctx->currmacro = NULL
end if
lex.ctx->lasttk_id = INVALID
''
lex.ctx->bufflen = 0
lex.ctx->deflen = 0
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
lex.ctx->buffptr = iif( is_fb_eval, @lex.ctx->buff, NULL )
lex.ctx->defptr = NULL
DZstrAllocate( lex.ctx->deftext, 0 )
else
lex.ctx->buffptrw = @lex.ctx->buffw
lex.ctx->defptrw = NULL
DWstrAllocate( lex.ctx->deftextw, 0 )
end if
''
if( is_fb_eval ) then
lex.ctx->filepos = (lex.ctx-1)->filepos
lex.ctx->lastfilepos = (lex.ctx-1)->lastfilepos
else
lex.ctx->filepos = 0
lex.ctx->lastfilepos = 0
end if
'' only if it's not on an inc file
if( (env.includerec = 0) or (is_fb_eval = TRUE) ) then
DZstrAllocate( lex.ctx->currline, 0 )
lex.insidemacro = FALSE
end if
lex.ctx->after_space = FALSE
if( (isinclude = FALSE) and (is_fb_eval = FALSE ) ) then
ppInit( )
end if
end sub
'':::::
sub lexEnd( )
pponly_ln = ""
ppEnd( )
end sub
private sub hCollectCharForDebugOutput( byval char as uinteger )
if( char < 32 ) then
'' Filter out ASCII control chars, as they really shouldn't be
'' emitted into .asm/.c, because, for example, &h17 (ETB, end of
'' transmission block) apparently causes GAS to stop early,
'' instead of reading until the rest of the .asm file, even if
'' it's inside a comment.
select case as const( char )
case 0, CHAR_CR, CHAR_LF
exit sub
'' Those white-space chars should be ok though
case CHAR_TAB, CHAR_VTAB, CHAR_FORMFEED
case else
char = asc( "?" )
end select
'' Unicode char? Can't be stored into lex.ctx->currline zstring,
'' and .asm/.c output files are ANSI/ASCII-only anyways.
elseif( char > 255 ) then
char = asc( "?" )
end if
DZstrConcatAssignC( lex.ctx->currline, char )
end sub
'':::::
private function hReadChar _
( _
_
) as uinteger
dim as uinteger char = any
'' any #define'd text?
if( lex.ctx->deflen > 0 ) then
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
char = *lex.ctx->defptr
else
char = *lex.ctx->defptrw
end if
'' update current line text (if not parsing an inc file)
if( env.clopt.debuginfo ) then
if( env.includerec = 0 ) then
if( lex.insidemacro = FALSE ) then
lex.insidemacro = TRUE
DZstrConcatAssign( lex.ctx->currline, " [Macro Expansion: " )
end if
hCollectCharForDebugOutput( char )
end if
end if
else
'' buffer empty?
if( lex.ctx->bufflen = 0 ) then
if( eof( env.inf.num ) = FALSE ) then
lex.ctx->filepos = seek( env.inf.num )
select case as const env.inf.format
case FBFILE_FORMAT_ASCII
if( get( #env.inf.num, , lex.ctx->buff ) = 0 ) then
lex.ctx->bufflen = seek( env.inf.num ) - lex.ctx->filepos
lex.ctx->buffptr = @lex.ctx->buff
end if
case FBFILE_FORMAT_UTF8
lexReadUTF8( )
case FBFILE_FORMAT_UTF16LE
lexReadUTF16LE( )
case FBFILE_FORMAT_UTF16BE
lexReadUTF16BE( )
case FBFILE_FORMAT_UTF32LE
lexReadUTF32LE( )
case FBFILE_FORMAT_UTF32BE
lexReadUTF32BE( )
end select
end if
end if
''
if( lex.ctx->bufflen > 0 ) then
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
char = *lex.ctx->buffptr
else
char = *lex.ctx->buffptrw
end if
else
char = 0
end if
'' update current line text (if not parsing an inc file)
if( env.clopt.debuginfo ) then
if( env.includerec = 0 ) then
if( lex.insidemacro ) then
lex.insidemacro = FALSE
DZstrConcatAssign( lex.ctx->currline, " ] " )
end if
hCollectCharForDebugOutput( char )
end if
end if
end if
function = char
end function
sub lexEatChar( )
if( lex.ctx->lahdchar1 = UINVALID ) then
'' No look-ahead char, read next char and force the next
'' lexCurrentChar() to update the current char.
hSkipChar( )
lex.ctx->currchar = UINVALID
elseif( lex.ctx->lahdchar2 = UINVALID ) then
'' Look ahead char is the next current char
lex.ctx->currchar = lex.ctx->lahdchar1
lex.ctx->lahdchar1 = UINVALID
else
'' Look ahead char is the next current char
'' and second look ahead char becomes look ahead char
lex.ctx->currchar = lex.ctx->lahdchar1
lex.ctx->lahdchar1 = lex.ctx->lahdchar2
lex.ctx->lahdchar2 = UINVALID
end if
end sub
function lexEatWhitespace( ) as integer
function = FALSE
if( lex.ctx->currchar = UINVALID ) then
lex.ctx->currchar = hReadChar( )
end if
do while( (lex.ctx->currchar = CHAR_TAB) or (lex.ctx->currchar = CHAR_SPACE) )
lex.ctx->after_space = TRUE
lexEatChar( )
lex.ctx->currchar = hReadChar( )
function = TRUE
loop
end function
'':::::
private sub hSkipChar
'' #define'd text?
if( lex.ctx->deflen > 0 ) then
lex.ctx->deflen -= 1
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
lex.ctx->defptr += 1
else
lex.ctx->defptrw += 1
end if
'' Reset the current macro if all expansion text is consumed now
if( lex.ctx->deflen = 0 ) then
lex.ctx->currmacro = NULL
end if
'' input stream (not EOF?)
elseif( lex.ctx->currchar <> 0 ) then
lex.ctx->bufflen -= 1
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
lex.ctx->buffptr += 1
else
lex.ctx->buffptrw += 1
end if
end if
end sub
'':::::
function lexCurrentChar _
( _
) as uinteger
if( lex.ctx->currchar = UINVALID ) then
lex.ctx->currchar = hReadChar( )
end if
function = lex.ctx->currchar
end function
'':::::
function lexGetLookAheadChar _
( _
) as uinteger
if( lex.ctx->lahdchar1 = UINVALID ) then
hSkipChar( )
lex.ctx->lahdchar1 = hReadChar( )
end if
function = lex.ctx->lahdchar1
end function
'':::::
function lexGetLookAheadChar2 _
( _
) as uinteger
'' internally, should never use this function unless there
'' is already a character in the look aead
assert( lex.ctx->lahdchar1 <> UINVALID )
if( lex.ctx->lahdchar2 = UINVALID ) then
hSkipChar( )
lex.ctx->lahdchar2 = hReadChar( )
end if
function = lex.ctx->lahdchar2
end function
''
''char classes:
''
''ALPHA 'A' - 'Z'
''DIGIT '0' - '9'
''HEXDIG 'A' - 'F' | DIGIT
''OCTDIG '0' - '7'
''BINDIG '0' | '1'
''ALPHADIGIT ALPHA | DIGIT
''ISUFFIX '%' | '&'
''FSUFFIX '!' | '#'
''SUFFIX ISUFFIX | FSUFFIX | '$'
''
''EXPCHAR 'D' | 'E'
''
''OPERATOR '=' | '<' | '>' | '+' | '-' | '*' | '/' | '\' | '^'
''DELIMITER '.' | ':' | ',' | ';' | '"' | '''
''
'':::::
''indentifier = (ALPHA | '_') { [ALPHADIGIT | '_' ] } [SUFFIX].
''
private sub hReadIdentifier _
( _
byval pid as zstring ptr, _
byref tlen as integer, _
byref dtype as integer, _
byref suffixchar as integer, _
byval flags as LEXCHECK _
)
dim as integer skipchar = any
'' (ALPHA | '_' )
*pid = lexCurrentChar( )
pid += 1
tlen += 1
suffixchar = CHAR_NULL
lexEatChar( )
skipchar = FALSE
'' { [ALPHADIGIT | '_' ] }
do
var c = lexCurrentChar( )
select case as const c
case CHAR_AUPP to CHAR_ZUPP, _
CHAR_ALOW to CHAR_ZLOW, _
CHAR_0 to CHAR_9, _
CHAR_UNDER
case CHAR_DOT
if( (flags and LEXCHECK_EATPERIOD) = 0 ) then
exit do
end if
case else
exit do
end select
lexEatChar( )
if( skipchar = FALSE ) then
'' no more room?
if( tlen = FB_MAXNAMELEN ) then
'' show warning?
if( (flags and LEXCHECK_NOLINECONT) = 0 ) then
'' just once..
flags or= LEXCHECK_NOLINECONT
errReportWarn( FB_WARNINGMSG_IDNAMETOOBIG )
end if
skipchar = TRUE
else
*pid = c
pid += 1
tlen += 1
end if
end if
loop
'' null-term
*pid = 0
'' [SUFFIX]
dtype = FB_DATATYPE_INVALID
#if 0
'' Possible method to disallow suffixes on identifiers in -lang fb
'' completely would be to not read them. No nead to report error
'' or warning. The parser should report an error when it gets an
'' invalid token on it's own.
''
if( fbLangOptIsSet( FB_LANG_OPT_SUFFIX ) = FALSE ) then
exit sub
end if
#endif
if( (flags and LEXCHECK_NOSUFFIX) = 0 ) then
select case as const lexCurrentChar( )
'' '%'?
case FB_TK_INTTYPECHAR
dtype = env.lang.integerkeyworddtype
suffixchar = FB_TK_INTTYPECHAR
lexEatChar( )
'' '&'?
case FB_TK_LNGTYPECHAR
dtype = FB_DATATYPE_LONG
suffixchar = FB_TK_LNGTYPECHAR
lexEatChar( )
'' '!'?
case FB_TK_SNGTYPECHAR
dtype = FB_DATATYPE_SINGLE
suffixchar = FB_TK_SNGTYPECHAR
lexEatChar( )
'' '#'?
case FB_TK_DBLTYPECHAR '' alias for CHAR_SHARP
'' isn't it a '##'?
if( lexGetLookAheadChar( ) <> FB_TK_DBLTYPECHAR ) then
dtype = FB_DATATYPE_DOUBLE
suffixchar = FB_TK_DBLTYPECHAR
lexEatChar( )
end if
'' '$'?
case FB_TK_STRTYPECHAR
dtype = FB_DATATYPE_STRING
suffixchar = FB_TK_STRTYPECHAR
lexEatChar( )
end select
end if
end sub
''::::
''hex_oct_bin = '&' OCTDIG+
'' | '&' 'H' HEXDIG+
'' | '&' 'O' OCTDIG+
'' | '&' 'B' BINDIG+
''
private function hReadNonDecNumber _
( _
byref pnum as zstring ptr, _
byref tlen as integer, _
byref dtype as integer, _
byval flags as LEXCHECK _
) as ulongint
dim as uinteger value = any, c = any, first_c = any
dim as ulongint value64 = any
dim as integer lgt = any, havedigits = any
dim as integer skipchar = any
assert( dtype = FB_DATATYPE_SHORT )
value = 0
lgt = 0
skipchar = FALSE
havedigits = FALSE
#if __FB_DEBUG__
'' expect that hReadNonDecNumber( ) was called with '&' in lexCurrentChar( )
c = lexCurrentChar( )
assert( c = CHAR_AMP )
#endif
c = lexGetLookAheadChar( )
'' and octal number immediately after '&' indicates octal
select case as const c
case CHAR_0 to CHAR_7
c = CHAR_OUPP
'' don't lexEatChar( ) here, case CHAR_OUPP, CHAR_OLOW
'' will take take of it below
case else
'' no octal char is next so consume the char and lex normally
'' '&'
lexEatChar( )
end select
select case as const c
'' hex
case CHAR_HUPP, CHAR_HLOW
pnum[0] = CHAR_AMP
pnum[1] = c
pnum += 2
tlen += 2
lexEatChar( )
'' skip leading zeroes if not inside a comment or parsing an $include
if( (flags and (LEXCHECK_NOLINECONT or LEXCHECK_NOSUFFIX)) = 0 ) then
while( lexCurrentChar( ) = CHAR_0 )
*pnum = CHAR_0
pnum += 1
tlen += 1
lexEatChar( )
havedigits = TRUE
wend
end if
do
c = lexCurrentChar( )
select case c
case CHAR_ALOW to CHAR_FLOW, CHAR_AUPP to CHAR_FUPP, CHAR_0 to CHAR_9
lexEatChar( )
havedigits = TRUE
if( skipchar = FALSE ) then
*pnum = c
pnum += 1
tlen += 1
c -= CHAR_0
if( c > 9 ) then
c -= (CHAR_AUPP - CHAR_9 - 1)
end if
if( c > 16 ) then
c -= (CHAR_ALOW - CHAR_AUPP)
end if
lgt += 1
if( lgt > 8 ) then
if( lgt = 9 ) then
dtype = FB_DATATYPE_LONGINT
value64 = (culngint( value ) * 16) + c
elseif( lgt = 17 ) then
if( (flags and LEXCHECK_NOLINECONT) = 0 ) then
errReportWarn( FB_WARNINGMSG_NUMBERTOOBIG )
end if
skipchar = TRUE
else
value64 = (value64 * 16) + c
end if
else
if( lgt = 5 ) then
dtype = FB_DATATYPE_LONG
end if
value = (value * 16) + c
end if
end if
case else
exit do
end select
loop
'' oct
case CHAR_OUPP, CHAR_OLOW
pnum[0] = CHAR_AMP
pnum[1] = c
pnum += 2
tlen += 2
lexEatChar( )
'' skip leading zeroes if not inside a comment or parsing an $include
if( (flags and (LEXCHECK_NOLINECONT or LEXCHECK_NOSUFFIX)) = 0 ) then
while( lexCurrentChar( ) = CHAR_0 )
*pnum = CHAR_0
pnum += 1
tlen += 1
lexEatChar( )
havedigits = TRUE
wend
end if
first_c = lexCurrentChar( )
do
c = lexCurrentChar( )
select case c
case CHAR_0 to CHAR_7
lexEatChar( )
havedigits = TRUE
if( skipchar = FALSE ) then
*pnum = c
pnum += 1
tlen += 1
c -= CHAR_0
lgt += 1
if( lgt > 10 ) then
select case as const lgt
case 11
if( first_c > CHAR_3 ) then
dtype = FB_DATATYPE_LONGINT
value64 = (culngint( value ) * 8) + c
else
value = (value * 8) + c
end if
case 12
if( typeGetSize( dtype ) < 8 ) then
dtype = FB_DATATYPE_LONGINT
value64 = culngint( value )
end if
value64 = (value64 * 8) + c
case 22
if( first_c > CHAR_1 ) then
if( (flags and LEXCHECK_NOLINECONT) = 0 ) then
errReportWarn( FB_WARNINGMSG_NUMBERTOOBIG )
end if
skipchar = TRUE
else
value64 = (value64 * 8) + c
end if
case 23
if( (flags and LEXCHECK_NOLINECONT) = 0 ) then
errReportWarn( FB_WARNINGMSG_NUMBERTOOBIG )
end if
skipchar = TRUE
case else
value64 = (value64 * 8) + c
end select
else
if( lgt = 6 ) then
if( first_c > CHAR_1 ) then
dtype = FB_DATATYPE_LONG
end if
elseif( lgt = 7 ) then
dtype = FB_DATATYPE_LONG
end if
value = (value * 8) + c
end if
end if
case else
exit do
end select
loop
'' bin
case CHAR_BUPP, CHAR_BLOW
pnum[0] = CHAR_AMP
pnum[1] = c
pnum += 2
tlen += 2
lexEatChar( )
'' skip leading zeroes if not inside a comment or parsing an $include
if( (flags and (LEXCHECK_NOLINECONT or LEXCHECK_NOSUFFIX)) = 0 ) then
while( lexCurrentChar( ) = CHAR_0 )
*pnum = CHAR_0
pnum += 1
tlen += 1
lexEatChar( )
havedigits = TRUE
wend
end if
do
c = lexCurrentChar( )
select case c
case CHAR_0, CHAR_1
lexEatChar( )
havedigits = TRUE
if( skipchar = FALSE ) then
*pnum = c
pnum += 1
tlen += 1
c -= CHAR_0
lgt += 1
if( lgt > 32 ) then
if( lgt = 33 ) then
dtype = FB_DATATYPE_LONGINT
value64 = (culngint( value ) * 2) + c
elseif( lgt = 65 ) then
if( (flags and LEXCHECK_NOLINECONT) = 0 ) then
errReportWarn( FB_WARNINGMSG_NUMBERTOOBIG )
end if
skipchar = TRUE
else
value64 = (value64 * 2) + c
end if
else
if( lgt = 17 ) then
dtype = FB_DATATYPE_LONG
end if
value = (value * 2) + c
end if
end if
case else
exit do
end select
loop
case else
exit function
end select
'' lgt havedigits
'' 0 FALSE no numbers, show a warning and recover
'' 0 TRUE all leading zeroes, truncate to single zero
'' >0 FALSE not possible - do nothing here
'' >0 TRUE normal number - do nothing here
'' no number or only leading zeros?
if( lgt = 0 ) then
'' no digits at all? show a warning
if( havedigits = FALSE ) then
if( (flags and (LEXCHECK_NOLINECONT or LEXCHECK_NOSUFFIX)) = 0 ) then
errReportWarn( FB_WARNINGMSG_EXPECTEDDIGIT )
end if
end if
'' truncate or recover with a single 0
*pnum = CHAR_0
pnum += 1
tlen += 1
end if
if( typeGetSize( dtype ) < 8 ) then
function = value
else
function = value64
end if
end function
'':::::
''float = DOT DIGIT { DIGIT } [FSUFFIX | { EXPCHAR [opadd] DIGIT { DIGIT } } | ].
''
private sub hReadFloatNumber _
( _
byref pnum as zstring ptr, _
byref t as FBTOKEN, _
byval hasdot as integer, _
byval flags as LEXCHECK _
)
dim as uinteger c = any
dim as integer llen = any
dim as integer skipchar = any
t.dtype = env.lang.floatliteraldtype
llen = t.len
skipchar = FALSE
'' DIGIT { DIGIT }
do
c = lexCurrentChar( )
select case c
case CHAR_0 to CHAR_9
lexEatChar( )
if( skipchar = FALSE ) then
*pnum = c
pnum += 1
t.len += 1
end if
case else
exit do
end select
'' no more room?
if( t.len = FB_MAXNUMLEN ) then
'' not set yet?
if( skipchar = FALSE ) then
skipchar = TRUE
else
'' show warning?
if( (flags and LEXCHECK_NOLINECONT) = 0 ) then
'' just once..
flags or= LEXCHECK_NOLINECONT
errReportWarn( FB_WARNINGMSG_NUMBERTOOBIG )
end if
end if
end if
loop
if( t.len > 7 + iif( hasdot, 1, 0 ) ) then
t.dtype = FB_DATATYPE_DOUBLE
end if
'' [FSUFFIX | { EXPCHAR [opadd] DIGIT { DIGIT } } | ]
c = lexCurrentChar( )
select case as const c
'' 'e', 'E', 'd', 'D'?
case CHAR_ELOW, CHAR_EUPP, CHAR_DLOW, CHAR_DUPP
'' EXPCHAR
if( c = CHAR_DLOW or c = CHAR_DUPP ) then
t.dtype = FB_DATATYPE_DOUBLE
end if
if( skipchar = FALSE ) then
if( flags = LEXCHECK_EVERYTHING ) then
'' make sure exp char is an 'e'
'' (Val should accept 'd's, so may not be necessary now...)
c = CHAR_ELOW
end if
*pnum = c
pnum += 1
t.len += 1
end if
lexEatChar( )
'' [opadd]
c = lexCurrentChar( )
if( (c = CHAR_PLUS) or (c = CHAR_MINUS) ) then
lexEatChar( )
if( skipchar = FALSE ) then
*pnum = c
pnum += 1
t.len += 1
end if
end if
do
c = lexCurrentChar( )
select case as const c
case CHAR_0 to CHAR_9
lexEatChar( )
if( skipchar = FALSE ) then
*pnum = c
pnum += 1
t.len += 1
end if
case else
exit do
end select
'' no more room?
if( t.len = FB_MAXNUMLEN ) then
'' not set yet?
if( skipchar = FALSE ) then
skipchar = TRUE
else
'' show warning?
if( (flags and LEXCHECK_NOLINECONT) = 0 ) then
'' just once..
flags or= LEXCHECK_NOLINECONT
errReportWarn( FB_WARNINGMSG_NUMBERTOOBIG )
end if
end if
end if
loop
end select
select case as const lexCurrentChar( )
'' 'F', 'f'?
case CHAR_FUPP, CHAR_FLOW
t.dtype = FB_DATATYPE_SINGLE
if( (flags and (LEXCHECK_NOSUFFIX or LEXCHECK_NOLETTERSUFFIX)) = 0 ) then
lexEatChar( )
end if
'' '!'
case FB_TK_SNGTYPECHAR
t.dtype = FB_DATATYPE_SINGLE
if( (flags and LEXCHECK_NOSUFFIX) = 0 ) then
lexEatChar( )
end if
'' '#'?
case FB_TK_DBLTYPECHAR '' alias for CHAR_SHARP
t.dtype = FB_DATATYPE_DOUBLE
if( (flags and LEXCHECK_NOSUFFIX) = 0 ) then
lexEatChar( )
end if
end select
if( flags = LEXCHECK_EVERYTHING ) then
if( t.len - llen = 0 ) then
'' '0'
*pnum = CHAR_0
pnum += 1
t.len += 1
end if
endif
end sub
private sub readNumberChars _
( _
byref t as FBTOKEN, _
byref flags as LEXCHECK, _
byref pnum as zstring ptr, _
byref skipchar as integer, _
byref value as ulongint _
)
'' Skip leading zeroes if not inside a comment or parsing an $include
var save_first_leading_zero = ((flags and (LEXCHECK_NOLINECONT or LEXCHECK_NOSUFFIX)) <> 0)
dim value_prev as ulongint