diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-04-14 20:47:59 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-04-14 20:47:59 -0700 |
commit | 4c97482494e6170733f4b2143199cff3abec5419 (patch) | |
tree | 8e609fb6ea8912ce92092f33cce2f70da50e1a0b | |
parent | f1a5e50f78927a362f244f0adfc1d23813c93073 (diff) | |
download | txr-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-- | ChangeLog | 9 | ||||
-rw-r--r-- | parser.l | 33 |
2 files changed, 28 insertions, 14 deletions
@@ -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. @@ -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; } |