]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
a68: implement GNU68-2026-001-short-of-symbol
authorJose E. Marchesi <jemarch@gnu.org>
Thu, 29 Jan 2026 02:33:17 +0000 (03:33 +0100)
committerJose E. Marchesi <jemarch@gnu.org>
Thu, 29 Jan 2026 11:06:10 +0000 (12:06 +0100)
This patch implements the GNU extension:

  GNU68-2026-001-brief-selection - Brief style for selection

which adds the preferred brief style for selection recommended by
Hansen in "ALGOL 68 Hardware Represenatation Recommendations"
published in the Algol Bulletin issue 42.

This extension is already listed in https://algol68-lang.org.

Signed-off-by: Jose E. Marchesi <jemarch@gnu.org>
gcc/algol68/ChangeLog

* ga68.vw: Update formal grammar to express the GNU extension.
* a68-parser.cc (a68_dont_mark_here): Likewise.
* a68-parser-scanner.cc (SINGLE_QUOTE_CHAR): Define.
(get_next_token): Recognize ' as QUOTE_SYMBOL.
(tokenise_source): Acknowledge QUOTE_SYMBOL.
* a68-parser-keywords.cc (a68_set_up_tables): Likewise.
* a68-parser-bottom-up.cc (reduce_primary_parts): Adjust parser to
brief form of selection.
* a68-parser-attrs.def (QUOTE_SYMBOL): New attribute.
* ga68.texi (Brief selection): New section.

gcc/testsuite/ChangeLog

* algol68/compile/error-selector-1.a68: New test.
* algol68/execute/selection-2.a68: Update test.
* algol68/execute/selection-5.a68: Likewise.

gcc/algol68/a68-parser-attrs.def
gcc/algol68/a68-parser-bottom-up.cc
gcc/algol68/a68-parser-keywords.cc
gcc/algol68/a68-parser-scanner.cc
gcc/algol68/a68-parser.cc
gcc/algol68/ga68.texi
gcc/algol68/ga68.vw
gcc/testsuite/algol68/compile/error-selector-1.a68 [new file with mode: 0644]
gcc/testsuite/algol68/execute/selection-2.a68
gcc/testsuite/algol68/execute/selection-5.a68

index e9cadd30cab20a45d95d8412b6b6995aec6ead8c..2d615409da1bcd2faae7c9e91c4b43646254c4d8 100644 (file)
@@ -305,6 +305,7 @@ A68_ATTR(PROCEDURING, "proceduring coercion")
 A68_ATTR(PROC_SYMBOL, "proc-symbol")
 A68_ATTR(PUBLIC_SYMBOL, "public-symbol")
 A68_ATTR(QUALIFIER, "qualifier")
+A68_ATTR(QUOTE_SYMBOL,"quote-symbol")
 A68_ATTR(RADIX_FRAME, "radix frame")
 A68_ATTR(REAL_DENOTATION, "real denotation")
 A68_ATTR(REAL_PATTERN, "real pattern")
index 14f914aeb27246d164f7c3c16af115fc957c6cc3..f1b06b1fbd328fa38fe967c2b1b66e991ec65e39 100644 (file)
@@ -1196,12 +1196,14 @@ reduce_primary_parts (NODE_T *p, enum a68_attribute expect)
 {
   for (NODE_T *q = p; q != NO_NODE; FORWARD (q))
     {
-      if (a68_whether (q, IDENTIFIER, OF_SYMBOL, STOP))
+      if (a68_whether (q, IDENTIFIER, OF_SYMBOL, STOP)
+         || a68_whether (q, IDENTIFIER, QUOTE_SYMBOL, STOP))
        ATTRIBUTE (q) = FIELD_IDENTIFIER;
 
       reduce (q, NO_NOTE, NO_TICK, NIHIL, NIL_SYMBOL, STOP);
       reduce (q, NO_NOTE, NO_TICK, SKIP, SKIP_SYMBOL, STOP);
       reduce (q, NO_NOTE, NO_TICK, SELECTOR, FIELD_IDENTIFIER, OF_SYMBOL, STOP);
+      reduce (q, NO_NOTE, NO_TICK, SELECTOR, FIELD_IDENTIFIER, QUOTE_SYMBOL, STOP);
       /* JUMPs without GOTO are resolved later.  */
       reduce (q, NO_NOTE, NO_TICK, JUMP, GOTO_SYMBOL, IDENTIFIER, STOP);
       reduce (q, NO_NOTE, NO_TICK, DENOTATION, LONGETY, INT_DENOTATION, STOP);
index 427e2b359fdf667ce55f8ca5ec565a24e67701a3..fe157dcdfb12539ac8b01a5236fa949405b101c7 100644 (file)
@@ -147,6 +147,7 @@ a68_set_up_tables (void)
       add_keyword (&A68 (top_keyword), ORF_SYMBOL, "OREL");
       add_keyword (&A68 (top_keyword), BRIEF_COMMENT_BEGIN_SYMBOL, "{");
       add_keyword (&A68 (top_keyword), BRIEF_COMMENT_END_SYMBOL, "}");
+      add_keyword (&A68 (top_keyword), QUOTE_SYMBOL, "'");
 
       if (OPTION_STROPPING (&A68_JOB) != SUPPER_STROPPING)
        {
index 39f762862474e42cd3a89b446d8dea2901668ae4..8c8b06464fed7100a5ed71befc268da335807225 100644 (file)
@@ -77,6 +77,7 @@ supper_postlude[] = {
 #define STOP_CHAR 127
 #define FORMFEED_CHAR '\f'
 #define CR_CHAR '\r'
+#define SINGLE_QUOTE_CHAR '\''
 #define QUOTE_CHAR '"'
 #define APOSTROPHE_CHAR '\''
 #define BACKSLASH_CHAR '\\'
@@ -1631,6 +1632,13 @@ get_next_token (bool in_format,
          *att = POINT_SYMBOL;
        }
     }
+  else if (!OPTION_STRICT (&A68_JOB) && c == SINGLE_QUOTE_CHAR)
+    {
+      c = next_char (ref_l, ref_s, true);
+      (sym++)[0] = SINGLE_QUOTE_CHAR;
+      sym[0] = '\0';
+      *att = QUOTE_SYMBOL;
+    }
   else if (ISDIGIT (c))
     {
       /* Something that begins with a digit:
@@ -2213,6 +2221,7 @@ tokenise_source (NODE_T **root, int level, bool in_format,
                case ESAC_SYMBOL:
                case OD_SYMBOL:
                case OF_SYMBOL:
+               case QUOTE_SYMBOL:
                case FI_SYMBOL:
                case CLOSE_SYMBOL:
                case BUS_SYMBOL:
index 1504e4dc25bdd3e206eaff68d0682b8e6a5f188d..939dbdde2eceba90976b7c76a9bca9ae50936f3e 100644 (file)
@@ -377,6 +377,7 @@ a68_dont_mark_here (NODE_T *p)
     case NIL_SYMBOL:
     case OD_SYMBOL:
     case OF_SYMBOL:
+    case QUOTE_SYMBOL:
     case OPEN_SYMBOL:
     case OP_SYMBOL:
     case ORF_SYMBOL:
index 6798b3a3761fdb27f107bb761767c4519e3c309d..64d9b316d58fb677cec053ac266a914bfdd77d92 100644 (file)
@@ -3364,6 +3364,7 @@ invoking the compiler.
 @menu
 * @code{@B{bin}} and @code{@B{abs}} of negative integral values::
 * Bold taggles::              Using underscores in mode and operator indications.
+* Brief selection::           Shorter form of the @code{of-symbol}.
 @end menu
 
 @node @code{@B{bin}} and @code{@B{abs}} of negative integral values
@@ -3484,6 +3485,28 @@ like @code{Foo__bar} and @code{_Baz} are not valid indications.
 Bold taggles are available when the gnu68 dialect of the language is
 selected.  @xref{Dialect options}.
 
+@node Brief selection
+@section Brief selection
+
+It was early recognized that a shorter alternative representation the
+of-symbol was very much needed, considering the fact the bold version
+@code{@B{of}} is at least four characters long.  This makes certain
+phrases long and also slightly laborious to read, like in:
+
+@example
+@B{pub} @B{op} + = (@B{Pos} a,b) @B{Pos}: (c @B{of} a + c @B{of} b, r @B{of} a + r @B{of} b),
+       - = (@B{Pos} a,b) @B{Pos}: (c @B{of} a - c @B{of} b, r @B{of} a - r @B{of} b);
+@end example
+
+This compiler allows using a quote character @code{'} instead of
+@code{of} in selections of structs and multiples.  Using this brief
+style the example above now can be written as:
+
+@example
+@B{pub} @B{op} + = (@B{Pos} a,b) @B{Pos}: (c'a + c'b, r'a + r'b),
+       - = (@B{Pos} a,b) @B{Pos}: (c'a - c'b, r'a - r'b);
+@end example
+
 @include gpl_v3.texi
 @include fdl.texi
 
index 77acf0f95d6c8ddcec28f4267a279cf4e42c7350..419d230e7a4acb3ed4b893c8fa23f36440b2b859 100644 (file)
@@ -40,6 +40,9 @@
   [NC] This is the GNU68-2025-005-nestable-comments GNU extension.  It
        adds support for nestable block comments.
 
+  [BF] This is the GNU68-2026-001-brief-selection GNU extension.  It
+       adds support for a brief form of the selection construct.
+
   The metaproduction rules, hyper-rules and hyper-alternatives
   introduced by each extension are clearly marked in the sections
   below.  You can easily search for them using the extensions tags in
@@ -388,7 +391,7 @@ k) *vacuum : EMPTY PACK.
 3.4.1 Syntax
 
 A) CHOICE :: choice using boolean ; CASE.
-B) CASE :: choice using intgral ; choice using UNITED.
+B) CASE :: choice using integral ; choice using UNITED.
 
 a) SOID NEST1 CHOICE clause{5D,551a,A341h,A349a} :
      CHOICE STYLE start{91a,-},
@@ -1060,13 +1063,16 @@ a) strong reference to MODE NEST nihil{5B} :
 
 5.3.1.1 Syntax
 
+{ Extensions:
+  [BF] brief selection }
+
 A) REFETY :: REF to ; EMPTY.
 B) REFLEXETY :: REF to ; REF to flexible ; EMPTY.
 
 a) REFETY MODE1 NEST selection{5C} :
      MODE1 field FIELDS applied field selector with TAG{48d},
-       of{94f} token, weak REFLEXETY ROWS of structured with
-                           FIELDS mode NEST SECONDARY{5C},
+       STYLE selection token, weak REFLEXETY ROWS of structured with
+                                   FIELDS mode NEST SECONDARY{5C},
        where (REFETY) is derived from (REFLEXETY){b,c,-}.
 b) WHETHER (transient reference to) is derived from
            (REF to flexible){a,532,66a} :
@@ -1622,7 +1628,7 @@ d) CHOICE STYLE out{34l} :
        STYLE else{94f,-} token ;
      where (CHOICE) is (CASE), STYLE out{94f,-} token.
 e) CHOICE STYLE finish{34a} :
-     whre (CHOICE) is (choice using boolean),
+     where (CHOICE) is (choice using boolean),
        STYLE fi{94f,-} token ;
      where (CHOICE) is (CASE), STYLE esac{94f,-} token.
 f) NOTION token :
@@ -1674,7 +1680,8 @@ f) STYLE nestable comment item{e} :
   [CS] andth symbol, orel symbol
   [MR] access symbol, module symbol, def symbol, public symbol,
        postlude symbol, formal nest symbol, egg symbol
-  [US] unsafe symbol }
+  [US] unsafe symbol
+  [SS] brief of symbol }
 
 { This section of the Report doesn't describe syntax, but lists all
   the different symbols along with their representation in the
@@ -1694,6 +1701,8 @@ d) module symbol{49a}                   MODULE
    formal nest symbol{56b}              NEST
    egg symbol{A6a,c}                    EGG
 f) unsafe symbol{37a}                   UNSAFE
+   bold of symbol{53a}                  OF
+   brief of symbol{53a}                 '
 h) bold comment begin symbol{92a}       NOTE
    bold comment end symbol{92a}         ETON
    brief comment begin symbol{92a}      {
diff --git a/gcc/testsuite/algol68/compile/error-selector-1.a68 b/gcc/testsuite/algol68/compile/error-selector-1.a68
new file mode 100644 (file)
index 0000000..ccdd977
--- /dev/null
@@ -0,0 +1,6 @@
+{ dg-options "-std=algol68" }
+
+begin mode Foo = struct (int a,b);
+      a'b; { dg-error "unworthy" }
+      skip
+end
index 0d7b6c6730b5c19f1d8a673d970ec5df8043686d..3dbab94961954e2510a198854c1604ae8910e046 100644 (file)
@@ -2,8 +2,8 @@
 # Selecting a struct name results in sub-names.  #
 BEGIN MODE PERSON = STRUCT (INT age, REAL income, INT num children);
       PERSON person;
-      age OF person := 44;
-      income OF person := 999.99;
+      age'person := 44;
+      income'person := 999.99;
       num children OF person := 0;
       ASSERT (age OF person = 44);
       ASSERT (num children OF person = 0);
index fde72d53ade51c424f0dbb0bab7497e4cc989c35..720dd57c025f7dd47a1fd6dbd724565f06c840ae 100644 (file)
@@ -1,6 +1,4 @@
-# { dg-options "-fstropping=upper" }  #
-# pr UPPER pr  #
-BEGIN MODE JORL = STRUCT (INT i, REAL r);
-      REF JORL jorl = LOC JORL := (10, 3.14);
-      ASSERT (i OF jorl = 10)
-END
+begin mode Jorl = struct (int i, real r);
+      ref Jorl jorl = loc Jorl := (10, 3.14);
+      assert (i'jorl = 10)
+end