-
Notifications
You must be signed in to change notification settings - Fork 8
/
lexer.es
executable file
·1904 lines (1745 loc) · 46.9 KB
/
lexer.es
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
/* -*- mode: java; mode: font-lock; tab-width: 4; insert-tabs-mode: nil; indent-tabs-mode: nil -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is [Open Source Virtual Machine.].
*
* The Initial Developer of the Original Code is
* Adobe System Incorporated.
* Portions created by the Initial Developer are Copyright (C) 2004-2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Adobe AS3 Team
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
TODO
x lex break
x regexp literals
x punctuators
x string literals
x comments
x reserved words
o escapes
o number literals
*/
use namespace intrinsic;
namespace Char
{
use default namespace Char;
const EOS = 0;
const a = "a".charCodeAt(0);
const b = "b".charCodeAt(0);
const c = "c".charCodeAt(0);
const d = "d".charCodeAt(0);
const e = "e".charCodeAt(0);
const f = "f".charCodeAt(0);
const g = "g".charCodeAt(0);
const h = "h".charCodeAt(0);
const i = "i".charCodeAt(0);
const j = "j".charCodeAt(0);
const k = "k".charCodeAt(0);
const l = "l".charCodeAt(0);
const m = "m".charCodeAt(0);
const n = "n".charCodeAt(0);
const o = "o".charCodeAt(0);
const p = "p".charCodeAt(0);
const q = "q".charCodeAt(0);
const r = "r".charCodeAt(0);
const s = "s".charCodeAt(0);
const t = "t".charCodeAt(0);
const u = "u".charCodeAt(0);
const v = "v".charCodeAt(0);
const w = "w".charCodeAt(0);
const x = "x".charCodeAt(0);
const y = "y".charCodeAt(0);
const z = "z".charCodeAt(0);
const A = "A".charCodeAt(0);
const B = "B".charCodeAt(0);
const C = "C".charCodeAt(0);
const D = "D".charCodeAt(0);
const E = "E".charCodeAt(0);
const F = "F".charCodeAt(0);
const G = "G".charCodeAt(0);
const H = "H".charCodeAt(0);
const I = "I".charCodeAt(0);
const J = "J".charCodeAt(0);
const K = "K".charCodeAt(0);
const L = "L".charCodeAt(0);
const M = "M".charCodeAt(0);
const N = "N".charCodeAt(0);
const O = "O".charCodeAt(0);
const P = "P".charCodeAt(0);
const Q = "Q".charCodeAt(0);
const R = "R".charCodeAt(0);
const S = "S".charCodeAt(0);
const T = "T".charCodeAt(0);
const U = "U".charCodeAt(0);
const V = "V".charCodeAt(0);
const W = "W".charCodeAt(0);
const X = "X".charCodeAt(0);
const Y = "Y".charCodeAt(0);
const Z = "Z".charCodeAt(0);
const Zero = "0".charCodeAt(0);
const One = "1".charCodeAt(0);
const Two = "2".charCodeAt(0);
const Three = "3".charCodeAt(0);
const Four = "4".charCodeAt(0);
const Five = "5".charCodeAt(0);
const Six = "6".charCodeAt(0);
const Seven = "7".charCodeAt(0);
const Eight = "8".charCodeAt(0);
const Nine = "9".charCodeAt(0);
const Dot = ".".charCodeAt(0);
const Bang = "!".charCodeAt(0);
const Equal = "=".charCodeAt(0);
const Percent = "%".charCodeAt(0);
const Ampersand = "&".charCodeAt(0);
const Asterisk = "*".charCodeAt(0);
const Plus = "+".charCodeAt(0);
const Dash = "-".charCodeAt(0);
const Slash = "/".charCodeAt(0);
const BackSlash = "\\".charCodeAt(0);
const Comma = ",".charCodeAt(0);
const Colon = ":".charCodeAt(0);
const Semicolon = ";".charCodeAt(0);
const LeftAngle = "<".charCodeAt(0);
const RightAngle = ">".charCodeAt(0);
const Caret = "^".charCodeAt(0);
const Bar = "|".charCodeAt(0);
const QuestionMark = "?".charCodeAt(0);
const LeftParen = "(".charCodeAt(0);
const RightParen = ")".charCodeAt(0);
const LeftBrace = "{".charCodeAt(0);
const RightBrace = "}".charCodeAt(0);
const LeftBracket = "[".charCodeAt(0);
const RightBracket = "]".charCodeAt(0);
const Tilde = "~".charCodeAt(0);
const At = "@".charCodeAt(0);
const SingleQuote = "'".charCodeAt(0);
const DoubleQuote = "\"".charCodeAt(0);
const Space = " ".charCodeAt(0);
const Newline = "\n".charCodeAt();
function fromOctal (str)
: int
{
return parseInt (str);
}
function fromHex (str)
: int
{
return parseInt (str);
}
}
namespace Token
{
use default namespace Token
const firstTokenClass = -1
const Minus = firstTokenClass
const MinusMinus = Minus - 1
const Not = MinusMinus - 1
const NotEqual = Not - 1
const StrictNotEqual = NotEqual - 1
const Remainder = StrictNotEqual - 1
const RemainderAssign = Remainder - 1
const BitwiseAnd = RemainderAssign - 1
const LogicalAnd = BitwiseAnd - 1
const LogicalAndAssign = LogicalAnd - 1
const BitwiseAndAssign = LogicalAndAssign - 1
const LeftParen = BitwiseAndAssign - 1
const RightParen = LeftParen - 1
const Mult = RightParen - 1
const MultAssign = Mult - 1
const Comma = MultAssign - 1
const Dot = Comma - 1
const DoubleDot = Dot - 1
const TripleDot = DoubleDot - 1
const LeftDotAngle = TripleDot - 1
const Div = LeftDotAngle - 1
const DivAssign = Div - 1
const Colon = DivAssign - 1
const DoubleColon = Colon - 1
const SemiColon = DoubleColon - 1
const QuestionMark = SemiColon - 1
const At = QuestionMark - 1
const LeftBracket = At - 1
const RightBracket = LeftBracket - 1
const BitwiseXor = RightBracket - 1
const BitwiseXorAssign = BitwiseXor - 1
const LeftBrace = BitwiseXorAssign - 1
const BitwiseOr = LeftBrace - 1
const LogicalOr = BitwiseOr - 1
const LogicalOrAssign = LogicalOr - 1
const BitwiseOrAssign = LogicalOrAssign - 1
const RightBrace = BitwiseOrAssign - 1
const BitwiseNot = RightBrace - 1
const Plus = BitwiseNot - 1
const PlusPlus = Plus - 1
const PlusAssign = PlusPlus - 1
const LessThan = PlusAssign - 1
const LeftShift = LessThan - 1
const LeftShiftAssign = LeftShift - 1
const LessThanOrEqual = LeftShiftAssign - 1
const Assign = LessThanOrEqual - 1
const MinusAssign = Assign - 1
const Equal = MinusAssign - 1
const StrictEqual = Equal - 1
const GreaterThan = StrictEqual - 1
const GreaterThanOrEqual = GreaterThan - 1
const RightShift = GreaterThanOrEqual - 1
const RightShiftAssign = RightShift - 1
const UnsignedRightShift = RightShiftAssign - 1
const UnsignedRightShiftAssign = UnsignedRightShift - 1
/* reserved identifiers */
const Break = UnsignedRightShiftAssign - 1
const Case = Break - 1
const Catch = Case - 1
const Class = Catch - 1
const Continue = Class - 1
const Default = Continue - 1
const Delete = Default - 1
const Do = Delete - 1
const Else = Do - 1
const Enum = Else - 1
const Extends = Enum - 1
const False = Extends - 1
const Finally = False - 1
const For = Finally - 1
const Function = For - 1
const If = Function - 1
const In = If - 1
const InstanceOf = In - 1
const New = InstanceOf - 1
const Null = New - 1
const Return = Null - 1
const Super = Return - 1
const Switch = Super - 1
const This = Switch - 1
const Throw = This - 1
const True = Throw - 1
const Try = True - 1
const TypeOf = Try - 1
const Var = TypeOf - 1
const Void = Var - 1
const While = Void - 1
const With = While - 1
/* contextually reserved identifiers */
const Call = With - 1
const Cast = Call - 1
const Const = Cast - 1
const Decimal = Const - 1
const Double = Decimal - 1
const Dynamic = Double - 1
const Each = Dynamic - 1
const Eval = Each - 1
const Final = Eval - 1
const Get = Final - 1
const Has = Get - 1
const Implements = Has - 1
const Import = Implements - 1
const Int = Import - 1
const Interface = Int - 1
const Internal = Interface - 1
const Intrinsic = Internal - 1
const Is = Intrinsic - 1
const Let = Is - 1
const Namespace = Let - 1
const Native = Namespace - 1
const Number = Native - 1
const Override = Number - 1
const Package = Override - 1
const Precision = Package - 1
const Private = Precision - 1
const Protected = Private - 1
const Prototype = Protected - 1
const Public = Prototype - 1
const Rounding = Public - 1
const Standard = Rounding - 1
const Strict = Standard - 1
const To = Strict - 1
const Set = To - 1
const Static = Set - 1
const Type = Static - 1
const UInt = Type - 1
const Undefined = UInt - 1
const Use = Undefined - 1
const Xml = Use - 1
const Yield = Xml - 1
/* literals */
const AttributeIdentifier = Yield - 1
const BlockComment = AttributeIdentifier - 1
const DocComment = BlockComment - 1
const Eol = DocComment - 1
const Identifier = Eol - 1
// The interpretation of these 4 literal types can be done during lexing
const ExplicitDecimalLiteral = Identifier - 1
const ExplicitDoubleLiteral = ExplicitDecimalLiteral - 1
const ExplicitIntLiteral = ExplicitDoubleLiteral - 1
const ExplicitUIntLiteral = ExplicitIntLiteral - 1
// The interpretation of these 3 literal types is deferred until defn phase
const DecimalIntegerLiteral = ExplicitUIntLiteral - 1
const DecimalLiteral = DecimalIntegerLiteral - 1
const HexIntegerLiteral = DecimalLiteral - 1
const RegexpLiteral = HexIntegerLiteral - 1
const SlashSlashComment = RegexpLiteral - 1
const StringLiteral = SlashSlashComment - 1
const Space = StringLiteral - 1
const XmlLiteral = Space - 1
const XmlPart = XmlLiteral - 1
const XmlMarkup = XmlPart - 1
const XmlText = XmlMarkup - 1
const XmlTagEndEnd = XmlText - 1
const XmlTagStartEnd = XmlTagEndEnd - 1
// meta
const ERROR = XmlTagStartEnd - 1
const EOS = ERROR - 1
const BREAK = EOS - 1
const lastTokenClass = BREAK
const names = [
"<unused index>",
"minus",
"minusminus",
"not",
"notequals",
"strictnotequals",
"modulus",
"modulusassign",
"bitwiseand",
"logicaland",
"logicalandassign",
"bitwiseandassign",
"leftparen",
"rightparen",
"mult",
"multassign",
"comma",
"dot",
"doubledot",
"tripledot",
"leftdotangle",
"div",
"divassign",
"colon",
"doublecolon",
"semicolon",
"questionmark",
"at",
"leftbracket",
"rightbracket",
"bitwisexor",
"bitwisexorassign",
"leftbrace",
"bitwiseor",
"logicalor",
"logicalorassign",
"bitwiseorassign",
"rightbrace",
"bitwisenot",
"plus",
"plusplus",
"plusassign",
"lessthan",
"leftshift",
"leftshiftassign",
"lessthanorequals",
"assign",
"minusassign",
"equals",
"strictequals",
"greaterthan",
"greaterthanorequals",
"rightshift",
"rightshiftassign",
"unsignedrightshift",
"unsignedrightshiftassign",
"break",
"case",
"catch",
"class",
"continue",
"default",
"delete",
"do",
"else",
"enum",
"extends",
"false",
"finally",
"for",
"function",
"if",
"in",
"instanceof",
"new",
"null",
"return",
"super",
"switch",
"this",
"throw",
"true",
"try",
"typeof",
"var",
"void",
"while",
"with",
"call",
"cast",
"const",
"decimal",
"double",
"dynamic",
"each",
"eval",
"final",
"get",
"has",
"implements",
"import",
"int",
"interface",
"internal",
"intrinsic",
"is",
"let",
"namespace",
"native",
"Number",
"override",
"package",
"precision",
"private",
"protected",
"prototype",
"public",
"rounding",
"standard",
"strict",
"to",
"set",
"static",
"type",
"uint",
"undefined",
"use",
"xml",
"yield",
"attributeidentifier",
"blockcomment",
"doccomment",
"eol",
"identifier",
"explicitdecimalliteral",
"explicitdoubleliteral",
"explicitintliteral",
"explicituintliteral",
"decimalintegerliteral",
"decimalliteral",
"hexintegerliteral",
"regexpliteral",
"linecomment",
"stringliteral",
"space",
"xmlliteral",
"xmlpart",
"xmlmarkup",
"xmltext",
"xmltagendend",
"xmltagstartend",
"ERROR",
"EOS",
"BREAK"
]
class Token
{
var kind
var utf8id
function Token(kind,utf8id)
{
this.kind = kind
this.utf8id = utf8id
}
function tokenText () : String
{
return this.utf8id;
}
}
const tokenStore = new Array;
function maybeReservedIdentifier (lexeme:String) : int
{
// ("maybeReservedIdentifier lexeme=",lexeme);
switch (lexeme) {
// ContextuallyReservedIdentifiers
case "break": return Break;
case "case": return Case;
case "catch": return Catch;
case "class": return Class;
case "continue": return Continue;
case "default": return Default;
case "delete": return Delete;
case "do": return Do;
case "else": return Else;
case "enum": return Enum;
case "extends": return Extends;
case "false": return False;
case "finally": return Finally;
case "for": return For;
case "function": return Function;
case "if": return If;
case "in": return In;
case "instanceof": return InstanceOf;
case "new": return New;
case "null": return Null;
case "return": return Return;
case "super": return Super;
case "switch": return Switch;
case "this": return This;
case "throw": return Throw;
case "true": return True;
case "try": return Try;
case "typeof": return TypeOf;
case "var": return Var;
case "void": return Void;
case "while": return While;
case "with": return With;
// ContextuallyReservedIdentifiers
case "call": return Call;
case "cast": return Cast;
case "const": return Const;
case "decimal": return Decimal;
case "double": return Double;
case "dynamic": return Dynamic;
case "each": return Each;
case "eval": return Eval;
case "final": return Final;
case "get": return Get;
case "has": return Has;
case "implements": return Implements;
case "import": return Import;
case "int": return Int;
case "interface" : return Interface;
case "internal": return Internal;
case "intrinsic": return Intrinsic;
case "is": return Is;
case "let": return Let;
case "namespace": return Namespace;
case "native": return Native;
case "Number": return Number;
case "override": return Override;
case "package": return Package;
case "precision": return Precision;
case "private": return Private;
case "protected": return Protected;
case "prototype": return Prototype;
case "public": return Public;
case "rounding": return Rounding;
case "standard": return Standard;
case "strict": return Strict;
case "to": return To;
case "set": return Set;
case "static": return Static;
case "to": return To;
case "type": return Type;
case "uint": return UInt;
case "undefined": return Undefined;
case "use": return Use;
case "xml": return Xml;
case "yield": return Yield;
default: return makeInstance (Identifier,lexeme);
}
}
function makeInstance(token_class:int, lexeme:String) : int
{
tokenStore.push(new Token(token_class, lexeme));
return tokenStore.length - 1;
}
function getTokenClass (tid : int) : int
{
// if the token id is negative, it is a token_class
if (tid < 0)
{
return tid;
}
// otherwise, get instance data from the instance vector.
var t : Token = tokens[tid];
return t.getTokenClass();
}
function tokenText ( tid : int ) : String
{
if (tid < 0) {
// if the token id is negative, it is a token_class.
var text = names[-tid];
}
else {
// otherwise, get instance data from the instance vector
var tok : Token = tokenStore[tid];
var text = tok.tokenText();
}
return text;
}
function test ()
{
for( let i = firstTokenClass; i >= lastTokenClass; --i )
print(i,": ",names[-i])
}
}
Token::test()
namespace Lexer
{
use default namespace Lexer;
class Scanner
{
private var tokenList : Array;
private var followsNewline : Boolean;
private var src : String;
private var origin : String;
private var curIndex : int;
private var markIndex : int;
public function Scanner (src:String, origin:String)
: src = src
, origin = origin
, tokenList = new Array
, curIndex = 0
, markIndex = 0
{
print("scanning: ",src);
}
public function next ()
: String
{
if (curIndex == src.length)
{
curIndex++;
return Char::EOS;
}
else
{
return src.charCodeAt(curIndex++);
}
}
public function lexeme()
: String
{
return src.slice (markIndex,curIndex)
}
public function retract()
: void
{
curIndex--;
// print("retract cur=",curIndex);
}
private function mark ()
: void
{
markIndex = curIndex;
// print("mark mark=",markIndex);
}
public function tokenList (lexPrefix)
: int
{
let tokenList = new Array;
let token = lexPrefix ();
tokenList.push (token);
while (token != Token::BREAK &&
token != Token::EOS &&
token != Token::ERROR)
{
token = start ();
tokenList.push (token);
}
return tokenList.reverse();
}
public function regexp ()
{
let c : int = next ();
switch (c)
{
case Char::Slash :
return regexpFlags ();
case Char::EOS :
throw "unexpected end of program in regexp literal";
default:
return regexp ();
}
}
public function regexpFlags ()
{
let c : int = next ();
if (Unicode.isIdentifierPart (String.fromCharCode(c))) {
return regexpFlags ();
}
else {
retract ();
return Token::makeInstance (Token::RegexpLiteral,lexeme());
}
}
public function start ()
: int
{
var c : int;
while (true)
{
mark();
c = next();
// print("c[",curIndex-1,"]=",String.fromCharCode(c));
switch (c)
{
case 0xffffffef: return utf8sig ();
case Char::EOS: return Token::EOS;
case Char::Slash: return slash ();
case Char::Newline: return Token::Newline;
case Char::Space: return start ();
case Char::LeftParen: return Token::LeftParen;
case Char::RightParen: return Token::RightParen;
case Char::Comma: return Token::Comma;
case Char::Semicolon: return Token::SemiColon;
case Char::QuestionMark: return Token::QuestionMark;
case Char::LeftBracket: return Token::LeftBracket;
case Char::RightBracket: return Token::RightBracket;
case Char::LeftBrace: return Token::LeftBrace;
case Char::RightBrace: return Token::RightBrace;
case Char::Tilde: return Token::BitwiseNot;
case Char::At: return Token::At;
case Char::SingleQuote: return stringLiteral (c);
case Char::DoubleQuote: return stringLiteral (c);
case Char::Dot: return dot ();
case Char::Dash: return minus ();
case Char::Bang: return not ();
case Char::Percent: return remainder ();
case Char::Ampersand: return and ();
case Char::Asterisk: return mult ();
case Char::Colon: return colon ();
case Char::Caret: return bitwiseXor ();
case Char::Bar: return bitwiseOr ();
case Char::Plus: return plus ();
case Char::LeftAngle: return leftAngle ();
case Char::Equal: return equal ();
case Char::RightAngle: return rightAngle ();
case Char::b: return b_ ();
case Char::c: return identifier ("c");
case Char::d: return d_ ();
case Char::e: return identifier ("e");
case Char::f: return identifier ("f");
case Char::g: return identifier ("g");
case Char::i: return identifier ("i");
case Char::n: return n_ ();
case Char::o: return identifier ("o");
case Char::p: return identifier ("p");
case Char::r: return identifier ("r");
case Char::s: return identifier ("s");
case Char::t: return identifier ("t");
case Char::u: return identifier ("u");
case Char::v: return identifier ("v");
case Char::w: return identifier ("w");
case Char::BackSlash:
let c = escapeSequence ();
return identifier (String.fromCharCode(c));
case Char::Zero: return zero ();
case Char::One:
case Char::Two:
case Char::Three:
case Char::Four:
case Char::Five:
case Char::Six:
case Char::Seven:
case Char::Eight:
case Char::Nine:
return decimalInteger ();
default:
if (Unicode.isIdentifierStart (String.fromCharCode(c)))
{
return identifier (String.fromCharCode(c));
}
else
{
return intrinsic::print("invalid prefix ", c);
}
}
}
Debug.assert(false);
}
private function zero ()
: int
{
let c : int = next ();
switch (c) {
case Char::x:
case Char::X:
return hexLiteral ();
case Char::Zero:
case Char::One:
case Char::Two:
case Char::Three:
case Char::Four:
case Char::Five:
case Char::Six:
case Char::Seven:
return octalLiteral ();
case Char::Dot:
return decimalInteger ();
case Char::Eight: // what do we do with these?
case Char::Nine:
default :
retract ();
return numberSuffix ();
}
}
private function hexLiteral ()
: int
{
let c : int = next ();
switch (c) {
case Char::Zero:
case Char::One:
case Char::Two:
case Char::Three:
case Char::Four:
case Char::Five:
case Char::Six:
case Char::Seven:
case Char::Eight:
case Char::Nine:
case Char::a: case Char::A:
case Char::b: case Char::B:
case Char::c: case Char::C:
case Char::d: case Char::D:
case Char::e: case Char::E:
case Char::f: case Char::F:
return hexLiteral ();
default:
retract ();
return numberSuffix ();
}
}
private function octalLiteral ()
: int
{
let c : int = next ();
switch (c) {
case Char::Zero:
case Char::One:
case Char::Two:
case Char::Three:
case Char::Four:
case Char::Five:
case Char::Six:
case Char::Seven:
return octalLiteral ();
case Char::Eight: // what do we do with these?
case Char::Nine:
default:
retract ();
return numberSuffix ();
}
}
private function decimalInteger ()
: int
{
let c : int = next ();
switch (c) {
case Char::Zero:
case Char::One:
case Char::Two:
case Char::Three:
case Char::Four:
case Char::Five:
case Char::Six:
case Char::Seven:
case Char::Eight:
case Char::Nine:
return decimalInteger ();
case Char::Dot:
return decimalFraction ();
case Char::e: case Char::E:
return decimalExponent ();
default:
retract ();
return numberSuffix ();
}
}
private function decimalFraction ()
: int
{
let c : int = next ();
switch (c) {
case Char::Zero:
case Char::One:
case Char::Two:
case Char::Three:
case Char::Four:
case Char::Five:
case Char::Six:
case Char::Seven:
case Char::Eight:
case Char::Nine:
return decimalFraction ();
case Char::e: case Char::E:
switch (next()) {
case Char::Plus:
case Char::Minus:
return decimalExponent ();
default:
retract ();
return decimalExponent ();
}
default:
retract ();
return numberSuffix ();
}
}
private function decimalExponent ()
: int
{
let c : int = next ();
switch (c) {
case Char::Zero:
case Char::One:
case Char::Two:
case Char::Three:
case Char::Four:
case Char::Five:
case Char::Six:
case Char::Seven:
case Char::Eight:
case Char::Nine:
return decimalExponent ();
default:
retract ();
return numberSuffix ();
}
}
private function numberSuffix ()