diff options
author | John Hodge <tpg@mutabah.net> | 2016-02-25 17:15:33 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-02-25 17:15:33 +0800 |
commit | 34312f9f8e7d281ca13792e79b46b88ac9f46d48 (patch) | |
tree | 280a47589fda86eaac7af90a9205d0d6e08876b3 /src | |
parent | 181291917323dc8412e4ca28d5ada992d359e15f (diff) | |
download | mrust-34312f9f8e7d281ca13792e79b46b88ac9f46d48.tar.gz |
Lex - Handle octal literals
Diffstat (limited to 'src')
-rw-r--r-- | src/parse/lex.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp index 260ca319..1e0e0712 100644 --- a/src/parse/lex.cpp +++ b/src/parse/lex.cpp @@ -308,13 +308,23 @@ Token Lexer::getTokenInt() throw ParseError::Generic("Invalid digit in binary literal"); } } - else if( isdigit(ch) ) { + else if( ch == 'o' ) { num_mode = OCT; - throw ParseError::Todo(*this, "Lex octal numbers"); + while( isdigit(ch = this->getc_num()) ) { + val *= 8; + if('0' <= ch && ch <= '7') + val += ch - '0'; + else + throw ParseError::Generic("Invalid digit in octal literal"); + } } else { num_mode = DEC; - val = 0; + while( isdigit(ch) ) { + val *= 10; + val += ch - '0'; + ch = this->getc_num(); + } } } else { |