| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 | 712 |
| 713 void Scanner::ScanDecimalDigits() { | 713 void Scanner::ScanDecimalDigits() { |
| 714 while (IsDecimalDigit(c0_)) | 714 while (IsDecimalDigit(c0_)) |
| 715 AddLiteralCharAdvance(); | 715 AddLiteralCharAdvance(); |
| 716 } | 716 } |
| 717 | 717 |
| 718 | 718 |
| 719 Token::Value Scanner::ScanNumber(bool seen_period) { | 719 Token::Value Scanner::ScanNumber(bool seen_period) { |
| 720 ASSERT(IsDecimalDigit(c0_)); // the first digit of the number or the fraction | 720 ASSERT(IsDecimalDigit(c0_)); // the first digit of the number or the fraction |
| 721 | 721 |
| 722 enum { DECIMAL, HEX, OCTAL } kind = DECIMAL; | 722 enum { DECIMAL, HEX, OCTAL, IMPLICIT_OCTAL, BINARY } kind = DECIMAL; |
| 723 | 723 |
| 724 LiteralScope literal(this); | 724 LiteralScope literal(this); |
| 725 if (seen_period) { | 725 if (seen_period) { |
| 726 // we have already seen a decimal point of the float | 726 // we have already seen a decimal point of the float |
| 727 AddLiteralChar('.'); | 727 AddLiteralChar('.'); |
| 728 ScanDecimalDigits(); // we know we have at least one digit | 728 ScanDecimalDigits(); // we know we have at least one digit |
| 729 | 729 |
| 730 } else { | 730 } else { |
| 731 // if the first character is '0' we must check for octals and hex | 731 // if the first character is '0' we must check for octals and hex |
| 732 if (c0_ == '0') { | 732 if (c0_ == '0') { |
| 733 int start_pos = source_pos(); // For reporting octal positions. | 733 int start_pos = source_pos(); // For reporting octal positions. |
| 734 AddLiteralCharAdvance(); | 734 AddLiteralCharAdvance(); |
| 735 | 735 |
| 736 // either 0, 0exxx, 0Exxx, 0.xxx, an octal number, or a hex number | 736 // either 0, 0exxx, 0Exxx, 0.xxx, a hex number, a binary number or |
| 737 // an octal number. |
| 737 if (c0_ == 'x' || c0_ == 'X') { | 738 if (c0_ == 'x' || c0_ == 'X') { |
| 738 // hex number | 739 // hex number |
| 739 kind = HEX; | 740 kind = HEX; |
| 740 AddLiteralCharAdvance(); | 741 AddLiteralCharAdvance(); |
| 741 if (!IsHexDigit(c0_)) { | 742 if (!IsHexDigit(c0_)) { |
| 742 // we must have at least one hex digit after 'x'/'X' | 743 // we must have at least one hex digit after 'x'/'X' |
| 743 return Token::ILLEGAL; | 744 return Token::ILLEGAL; |
| 744 } | 745 } |
| 745 while (IsHexDigit(c0_)) { | 746 while (IsHexDigit(c0_)) { |
| 746 AddLiteralCharAdvance(); | 747 AddLiteralCharAdvance(); |
| 747 } | 748 } |
| 749 } else if (c0_ == 'o' || c0_ == 'O') { |
| 750 kind = OCTAL; |
| 751 AddLiteralCharAdvance(); |
| 752 if (!IsOctalDigit(c0_)) { |
| 753 // we must have at least one octal digit after 'o'/'O' |
| 754 return Token::ILLEGAL; |
| 755 } |
| 756 while (IsOctalDigit(c0_)) { |
| 757 AddLiteralCharAdvance(); |
| 758 } |
| 759 } else if (c0_ == 'b' || c0_ == 'B') { |
| 760 kind = BINARY; |
| 761 AddLiteralCharAdvance(); |
| 762 if (!IsBinaryDigit(c0_)) { |
| 763 // we must have at least one binary digit after 'b'/'B' |
| 764 return Token::ILLEGAL; |
| 765 } |
| 766 while (IsBinaryDigit(c0_)) { |
| 767 AddLiteralCharAdvance(); |
| 768 } |
| 748 } else if ('0' <= c0_ && c0_ <= '7') { | 769 } else if ('0' <= c0_ && c0_ <= '7') { |
| 749 // (possible) octal number | 770 // (possible) octal number |
| 750 kind = OCTAL; | 771 kind = IMPLICIT_OCTAL; |
| 751 while (true) { | 772 while (true) { |
| 752 if (c0_ == '8' || c0_ == '9') { | 773 if (c0_ == '8' || c0_ == '9') { |
| 753 kind = DECIMAL; | 774 kind = DECIMAL; |
| 754 break; | 775 break; |
| 755 } | 776 } |
| 756 if (c0_ < '0' || '7' < c0_) { | 777 if (c0_ < '0' || '7' < c0_) { |
| 757 // Octal literal finished. | 778 // Octal literal finished. |
| 758 octal_pos_ = Location(start_pos, source_pos()); | 779 octal_pos_ = Location(start_pos, source_pos()); |
| 759 break; | 780 break; |
| 760 } | 781 } |
| 761 AddLiteralCharAdvance(); | 782 AddLiteralCharAdvance(); |
| 762 } | 783 } |
| 763 } | 784 } |
| 764 } | 785 } |
| 765 | 786 |
| 766 // Parse decimal digits and allow trailing fractional part. | 787 // Parse decimal digits and allow trailing fractional part. |
| 767 if (kind == DECIMAL) { | 788 if (kind == DECIMAL) { |
| 768 ScanDecimalDigits(); // optional | 789 ScanDecimalDigits(); // optional |
| 769 if (c0_ == '.') { | 790 if (c0_ == '.') { |
| 770 AddLiteralCharAdvance(); | 791 AddLiteralCharAdvance(); |
| 771 ScanDecimalDigits(); // optional | 792 ScanDecimalDigits(); // optional |
| 772 } | 793 } |
| 773 } | 794 } |
| 774 } | 795 } |
| 775 | 796 |
| 776 // scan exponent, if any | 797 // scan exponent, if any |
| 777 if (c0_ == 'e' || c0_ == 'E') { | 798 if (c0_ == 'e' || c0_ == 'E') { |
| 778 ASSERT(kind != HEX); // 'e'/'E' must be scanned as part of the hex number | 799 ASSERT(kind != HEX); // 'e'/'E' must be scanned as part of the hex number |
| 779 if (kind == OCTAL) return Token::ILLEGAL; // no exponent for octals allowed | 800 if (kind != DECIMAL) return Token::ILLEGAL; |
| 780 // scan exponent | 801 // scan exponent |
| 781 AddLiteralCharAdvance(); | 802 AddLiteralCharAdvance(); |
| 782 if (c0_ == '+' || c0_ == '-') | 803 if (c0_ == '+' || c0_ == '-') |
| 783 AddLiteralCharAdvance(); | 804 AddLiteralCharAdvance(); |
| 784 if (!IsDecimalDigit(c0_)) { | 805 if (!IsDecimalDigit(c0_)) { |
| 785 // we must have at least one decimal digit after 'e'/'E' | 806 // we must have at least one decimal digit after 'e'/'E' |
| 786 return Token::ILLEGAL; | 807 return Token::ILLEGAL; |
| 787 } | 808 } |
| 788 ScanDecimalDigits(); | 809 ScanDecimalDigits(); |
| 789 } | 810 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 Advance(); | 1101 Advance(); |
| 1081 } | 1102 } |
| 1082 } | 1103 } |
| 1083 literal.Complete(); | 1104 literal.Complete(); |
| 1084 | 1105 |
| 1085 next_.location.end_pos = source_pos() - 1; | 1106 next_.location.end_pos = source_pos() - 1; |
| 1086 return true; | 1107 return true; |
| 1087 } | 1108 } |
| 1088 | 1109 |
| 1089 } } // namespace v8::internal | 1110 } } // namespace v8::internal |
| OLD | NEW |