From 34312f9f8e7d281ca13792e79b46b88ac9f46d48 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 25 Feb 2016 17:15:33 +0800 Subject: Lex - Handle octal literals --- src/parse/lex.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') 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 { -- cgit v1.2.3