summaryrefslogtreecommitdiffstats
path: root/parser.l
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 /parser.l
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.
Diffstat (limited to 'parser.l')
-rw-r--r--parser.l33
1 files changed, 19 insertions, 14 deletions
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;
}