summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-04-14 20:47:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-04-14 20:47:59 -0700
commit4c97482494e6170733f4b2143199cff3abec5419 (patch)
tree8e609fb6ea8912ce92092f33cce2f70da50e1a0b
parentf1a5e50f78927a362f244f0adfc1d23813c93073 (diff)
downloadtxr-4c97482494e6170733f4b2143199cff3abec5419.tar.gz
txr-4c97482494e6170733f4b2143199cff3abec5419.tar.bz2
txr-4c97482494e6170733f4b2143199cff3abec5419.zip
Diagnose trailing junk in numeric literals.
* parser.l: Combining the handling of hex, octal and binary numeric literals into a single rule. Implementing an additional rule which diagnoses such tokens that have trailing junk. Thus, something like #x1F2AZ is now invalid syntax.
-rw-r--r--ChangeLog9
-rw-r--r--parser.l33
2 files changed, 28 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 4df75cc6..23b2704b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2015-04-14 Kaz Kylheku <kaz@kylheku.com>
+
+ Diagnose trailing junk in numeric literals.
+
+ * parser.l: Combining the handling of hex, octal and binary numeric
+ literals into a single rule. Implementing an additional rule which
+ diagnoses such tokens that have trailing junk. Thus, something
+ like #x1F2AZ is now invalid syntax.
+
2015-04-11 Kaz Kylheku <kaz@kylheku.com>
Implementing while* and until* loops.
diff --git a/parser.l b/parser.l
index dc163ac0..9121de12 100644
--- a/parser.l
+++ b/parser.l
@@ -225,39 +225,44 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return NUMBER;
}
-<SPECIAL,QSPECIAL,NESTED,BRACED>{XNUM} {
+<SPECIAL,QSPECIAL,NESTED,BRACED>({XNUM}|{ONUM}|{BNUM}) {
val str = string_own(utf8_dup_from(yytext + 2));
+ int base;
+
+ switch (yytext[1]) {
+ case 'x': base = 16; break;
+ case 'o': base = 8; break;
+ case 'b': default: base = 2; break;
+ }
if (yy_top_state(yyscanner) == INITIAL
|| yy_top_state(yyscanner) == QSILIT
|| yy_top_state(yyscanner) == QWLIT)
yy_pop_state(yyscanner);
- yylval->val = int_str(str, num(16));
+ yylval->val = int_str(str, num_fast(base));
return NUMBER;
}
-<SPECIAL,QSPECIAL,NESTED,BRACED>{ONUM} {
+<SPECIAL,QSPECIAL,NESTED,BRACED>({BNUM}|{ONUM}|{XNUM}){TOK} {
+ int base = 0;
val str = string_own(utf8_dup_from(yytext + 2));
- if (yy_top_state(yyscanner) == INITIAL
- || yy_top_state(yyscanner) == QSILIT
- || yy_top_state(yyscanner) == QWLIT)
- yy_pop_state(yyscanner);
-
- yylval->val = int_str(str, num(8));
- return NUMBER;
-}
+ switch (yytext[1]) {
+ case 'x': base = 16; break;
+ case 'o': base = 8; break;
+ case 'b': default: base = 2; break;
+ }
-<SPECIAL,QSPECIAL,NESTED,BRACED>{BNUM} {
- val str = string_own(utf8_dup_from(yytext + 2));
+ yyerrorf(yyg, lit("trailing junk in numeric literal: ~a~a~a"),
+ chr(yytext[0]), chr(yytext[1]), str, nao);
if (yy_top_state(yyscanner) == INITIAL
|| yy_top_state(yyscanner) == QSILIT
|| yy_top_state(yyscanner) == QWLIT)
yy_pop_state(yyscanner);
- yylval->val = int_str(str, num(2));
+ yylval->val = int_str(str, num_fast(base));
return NUMBER;
}