summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-08-12 21:04:04 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-08-12 21:04:04 -0700
commit0a2ef84a7a1c5e898c9fbf7c9e84a65d965212c6 (patch)
treeee225d5ba565d9c978f972eed14277b1c5564c80
parenta3cf3b0c03518a39391659da887f5dbe0ad5fc16 (diff)
downloadtxr-0a2ef84a7a1c5e898c9fbf7c9e84a65d965212c6.tar.gz
txr-0a2ef84a7a1c5e898c9fbf7c9e84a65d965212c6.tar.bz2
txr-0a2ef84a7a1c5e898c9fbf7c9e84a65d965212c6.zip
Floating-point constant tightening.
* parser.l (grammar): Change order of rule which recognizes FLODOT with a one-character trailing context other than a dot, and the rule which diagnoses trailing junk. The issue is that this order gives the wrong interpretation to 123.E, treating it as 123. followed by E rather than trailing junk, like in the case of 123.0E or 123.B. * txr.1: Adding the valid example 1.E5. Removing references to dot as consing dot. Fixed documentation which says that 1.E is 1 followed by a consing dot and E. The wrong behavior in fact produced 1.0 followed by E. No consing dot semantics.
-rw-r--r--parser.l16
-rw-r--r--txr.17
2 files changed, 12 insertions, 11 deletions
diff --git a/parser.l b/parser.l
index 2610a921..66a51cfc 100644
--- a/parser.l
+++ b/parser.l
@@ -287,8 +287,12 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return NUMBER;
}
-<SPECIAL,QSPECIAL,NESTED,BRACED>{FLODOT}/[^.] {
- val str = string_own(utf8_dup_from(yytext));
+<SPECIAL>({FLO}|{FLODOT}){TOK} |
+<BRACED>({FLO}|{FLODOT}){BTOK} |
+<NESTED>({FLO}|{FLODOT}){NTOK} {
+ val str = string_utf8(yytext);
+
+ yyerrorf(yyg, lit("trailing junk in floating-point literal: ~a"), str, nao);
if (yy_top_state(yyscanner) == INITIAL
|| yy_top_state(yyscanner) == QSILIT
@@ -299,12 +303,8 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return NUMBER;
}
-<SPECIAL>({FLO}|{FLODOT}){TOK} |
-<BRACED>({FLO}|{FLODOT}){BTOK} |
-<NESTED>({FLO}|{FLODOT}){NTOK} {
- val str = string_utf8(yytext);
-
- yyerrorf(yyg, lit("trailing junk in floating-point literal: ~a"), str, nao);
+<SPECIAL,QSPECIAL,NESTED,BRACED>{FLODOT}/[^.] {
+ val str = string_own(utf8_dup_from(yytext));
if (yy_top_state(yyscanner) == INITIAL
|| yy_top_state(yyscanner) == QSILIT
diff --git a/txr.1 b/txr.1
index 6ef3db2d..e9bf5832 100644
--- a/txr.1
+++ b/txr.1
@@ -2652,17 +2652,18 @@ Examples:
9.E19
-.5
+3E+3
+ 1.E5
.cble
Examples which are not floating-point constant tokens:
.cblk
- . ;; consing dot
+ . ;; dot token, not a number
123E ;; the symbol 123E
1.0E- ;; syntax error: invalid floating point constant
1.0E ;; syntax error: invalid floating point constant
- 1.E ;; 1; consing dot; symbol E
- .e ;; consing dot followed by symbol e
+ 1.E ;; syntax error: invalid floating point literal
+ .e ;; syntax error: dot token followed by symbol
.cble
In \*(TX there is a special "dotdot" token consisting of two consecutive periods.