diff options
author | pixel <pixel> | 2003-11-20 07:37:10 +0000 |
---|---|---|
committer | pixel <pixel> | 2003-11-20 07:37:10 +0000 |
commit | ebac9899fe2ef7a672d3728071b3a4179ec5a2df (patch) | |
tree | 818f3dbd9a016914b85571ff58a8ee44bab94c5d /lib/lua/src/llex.c | |
parent | 7741890b069ad9bad9748730e08f39d75a14c16a (diff) |
Adding Hexa and Octal syntax to lua's numbers
Diffstat (limited to 'lib/lua/src/llex.c')
-rw-r--r-- | lib/lua/src/llex.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/lua/src/llex.c b/lib/lua/src/llex.c index e3aea33..c859376 100644 --- a/lib/lua/src/llex.c +++ b/lib/lua/src/llex.c @@ -1,5 +1,5 @@ /*
-** $Id: llex.c,v 1.1 2003-11-06 11:56:07 pixel Exp $
+** $Id: llex.c,v 1.2 2003-11-20 07:37:10 pixel Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@@ -172,15 +172,34 @@ static size_t readname (LexState *LS) { /* LUA_NUMBER */
static void read_numeral (LexState *LS, int comma, SemInfo *seminfo) {
+ int oct = 0, hex = 0;
size_t l = 0;
checkbuffer(LS, l);
if (comma) save(LS, '.', l);
- while (isdigit(LS->current)) {
+ else if (LS->current == '0') {
+ oct = 1;
+ checkbuffer(LS, 1);
+ save_and_next(LS, l);
+ if (LS->current == 'x') {
+ oct = 0;
+ hex = 1;
+ checkbuffer(LS, 1);
+ save_and_next(LS, l);
+ }
+ }
+ while (isdigit(LS->current) || (hex && isxdigit(LS->current))) {
checkbuffer(LS, l);
save_and_next(LS, l);
}
+ checkbuffer(LS, 1);
if (LS->current == '.') {
save_and_next(LS, l);
+ if (hex || oct) {
+ save(LS, '\0', l);
+ luaX_lexerror(LS,
+ "error in number, mixing decimal point with octal or hexadecimal",
+ TK_NUMBER);
+ }
if (LS->current == '.') {
save_and_next(LS, l);
save(LS, '\0', l);
@@ -195,6 +214,12 @@ static void read_numeral (LexState *LS, int comma, SemInfo *seminfo) { }
if (LS->current == 'e' || LS->current == 'E') {
save_and_next(LS, l); /* read `E' */
+ if (hex || oct) {
+ save(LS, '\0', l);
+ luaX_lexerror(LS,
+ "error in number, mixing exponential with octal or hexadecimal",
+ TK_NUMBER);
+ }
if (LS->current == '+' || LS->current == '-')
save_and_next(LS, l); /* optional exponent sign */
while (isdigit(LS->current)) {
|