Skip to content

Commit 6839de7

Browse files
committed
a68: scanner fixes for bits denotations
This commit: 1. Fixes a bug in the scanner so it now checks whether the digits in a bits denotation are ok for its radix. 2. Does not allow to have typographical display features between the digits of bits denotations in SUPPER stropping, when the radix is 16. This is is avoid confusing situations like the one described in the comment below. 3. Adds a few tests. 4. Fixes an existing test that was assuming that bits denotations with radix 10 are allowed. The report allows radixes 2, 4, 8 and 16. Signed-off-by: Jose E. Marchesi <[email protected]> gcc/algol68/ChangeLog * a68-parser-scanner.cc (get_next_token): Bits denotation parsing fixes. * ga68.texi (SUPPER stropping): Document special rule for bits denotations with radix 16. gcc/testsuite/ChangeLog * algol68/compile/error-radix-1.a68: New test. * algol68/compile/radix-hex-upper-1.a68: Likewise. * algol68/compile/radix-hex-supper-1.a68: Likewise. * algol68/compile/error-radix-4.a68: Likewise. * algol68/compile/error-radix-3.a68: Likewise. * algol68/compile/error-radix-2.a68: Likewise. * algol68/execute/environment-enquiries-6.a68: Do not use radix 10 in bits denotations.
1 parent cc51567 commit 6839de7

File tree

9 files changed

+64
-7
lines changed

9 files changed

+64
-7
lines changed

gcc/algol68/a68-parser-scanner.cc

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,13 +1663,37 @@ get_next_token (bool in_format,
16631663
}
16641664
else if (is_radix_char (ref_l, ref_s, &c))
16651665
{
1666+
/* Parse the radix, which is expressed in base 10. */
16661667
(sym++)[0] = c;
1668+
char *end;
1669+
int64_t radix = strtol (A68_PARSER (scan_buf), &end, 10);
1670+
gcc_assert (end != A68_PARSER (scan_buf) && *end == 'r');
1671+
1672+
/* Get the rest of the bits literal. Typographical display features
1673+
are allowed in the reference language between the digit symbols
1674+
composing the denotation. However, in SUPPER stropping this could
1675+
lead to confusing situations like:
1676+
1677+
while bitmask /= 16r0 do ~ od
1678+
1679+
Where the scanner would recognize a bits denotation 16r0d and then
1680+
the parser would complain about a missing 'do'. This is not a
1681+
problem in UPPER stropping since D is not a valid hexadecimal
1682+
digit.
1683+
1684+
To avoid confusing errors, in SUPPER stropping we do not allow
1685+
typographical display features in bits denotations when the radix
1686+
is 16. */
16671687
c = next_char (ref_l, ref_s, true);
1668-
/* This is valid for both UPPER and SUPPER stropping. */
1669-
while (ISDIGIT (c) || strchr ("abcdef", c) != NO_TEXT)
1688+
while (((radix == 2 && (c == '0' || c == '1'))
1689+
|| (radix == 4 && (c >= '0' && c <= '3'))
1690+
|| (radix == 8 && (c >= '0' && c <= '7'))
1691+
|| (radix == 16 && (ISDIGIT (c) || strchr ("abcdef", c) != NO_TEXT))))
16701692
{
16711693
(sym++)[0] = c;
1672-
c = next_char (ref_l, ref_s, true);
1694+
c = next_char (ref_l, ref_s,
1695+
OPTION_STROPPING (&A68_JOB) != SUPPER_STROPPING
1696+
|| radix != 16);
16731697
}
16741698
*att = BITS_DENOTATION;
16751699
}

gcc/algol68/ga68.texi

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,10 @@ that, when they appear between symbols, are of no significance and do
13121312
not alter the meaning of the program. However, when a space or a tab
13131313
appear in string or character denotations, they represent the
13141314
@code{space symbol} and the @code{tab symbol}
1315-
respectively@footnote{The @code{tab symbol} is a GNU extension}.
1315+
respectively@footnote{The @code{tab symbol} is a GNU extension}. The
1316+
different stropping regimes, however, may impose specific restrictions
1317+
on where typographical display features may or may not
1318+
appear. @xref{Stropping regimes}.
13161319

13171320
@node Worthy characters
13181321
@section Worthy characters
@@ -1698,6 +1701,23 @@ The underscore characters are not really part of the tag, but part of
16981701
the stropping. For example, both @code{goto found_zero} and
16991702
@code{goto foundzero} jump to the same label.
17001703

1704+
In general, typographical display features are allowed between any
1705+
symbol in the written program. In SUPPER stropping, however, it is
1706+
not allowed to place spaces or tab characters between the constituent
1707+
digits of bits denotations when the radix is 16. This is to avoid
1708+
confusing situations like the following invalid program:
1709+
1710+
@example
1711+
@B{while} bitmask /= 16r0 @B{do} ~ @B{od}
1712+
@end example
1713+
1714+
@noindent
1715+
Where the bits denotation would be interpreted as @code{16r0d} rather
1716+
than @code{16r0}, leading to a syntax error. Note however that
1717+
typographical display features are still allowed between the radix
1718+
part and the digits, so @code{16r aabb} is valid also in SUPPER
1719+
stropping.
1720+
17011721
The @code{recsel output records} procedure, encoded in SUPPER
17021722
stropping, looks like below.
17031723

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(bits a = 2r03; skip) { dg-error "" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(bits b = 8r09; skip) { dg-error "" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(bits c = 8rab, skip) { dg-error "" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(bits d = 16rfg; skip) { dg-error "" }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{ Make sure that in supper stropping the bits
2+
denotation is parsed as 16rab and not 16rabd }
3+
while bits foo; foo /= 16r ab do ~ od
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# { dg-options "-fstropping=upper" } #
2+
3+
# Typographical display features are allowed between
4+
digit symbols in hexadecimal bits denotations in UPPER
5+
stropping. #
6+
WHILE BITS foo; foo /= 16r a b DO ~ OD
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# { dg-options "-fstropping=upper" } #
22
# Environment enquiries for SIZETY BITs #
3-
BEGIN ASSERT (max bits /= 10r0);
3+
BEGIN ASSERT (max bits /= 2r0);
44
# XXX use LENG max bits below #
5-
ASSERT (long max bits >= LONG 10r0);
6-
ASSERT (long long max bits >= LONG LONG 10r0)
5+
ASSERT (long max bits >= LONG 16r0);
6+
ASSERT (long long max bits >= LONG LONG 4r0)
77
END

0 commit comments

Comments
 (0)