Use of sppp.awk, part 2

chris hermansen clhermansen@gmail.com
Thu Feb 12 23:51:56 GMT 2026


Thanks, Jose!

On Thu, Feb 12, 2026 at 3:30 PM Jose E. Marchesi <jemarch@gnu.org> wrote:

>
> Hi Chris.
>
> The syntax changed at some point.  Example from the existing file
> transput.a68.in in the GCC source tree:
>
>           {iter L {} {long}    {long long}}
>           {iter K {} {LENG}    {LENG LENG}}
>           {iter S {} {SHORTEN} {SHORTEN SHORTEN}}
>           ({L} real x):
>              begin string s, int before := 0;
>                    {L} real y := x + {L} .5 * {L} .1 ** after;
>                    proc choosedig = (ref {L} real y) char:
>                       dig_char ((int c := {S} ENTIER (y *:= {L} 10.0); (c
> > 9 | c := 9);
>                                  y -:= {K} c; c));
>                    while y >= {L} 10.0 ** before do before +:= 1 od;
>                    y /:= {L} 10.0 ** before;
>                    to before do s +:= choosedig (y) od;
>                    (after > 0 | s +:= ".");
>                    to after do s +:= choosedig (y) od;
>                    (UPB s > width | width * errorchar | s)
>              end
>            {reti {,}}
>
> As you can see you put any number of {iter...} all of which are
> terminated by a single {reti}.  Yes I know that is not too elegant, but
> it was the most expeditive way to implement the preprocessor with a
> short awk script..
>

I tried this instead based on your example above:

 cat add.sppp-alt
prio {ℵ₀} ADD = 1;
op
{iter L {short short} {short} {} {long} {long long}}
{iter K {SHORTEN SHORTEN} {SHORTEN} {} {LENG} {LENG}}
{iter xlx {short_short_} {short_} {} {long_} {long_long_}}
ADD = (ref {L} int a, int d) bool:
  if {L} int amax = {xlx}max_int OVER {L} 10,
           dmax = {xlx}max_int MOD {L} 10;
    a > amax OR a = amax AND {K} d > dmax
  then false
  else a:= {L} 10 * a + {K} d; true
  fi
{reti {,}}
;

and sure enough, that worked perfectly!
-- 
Chris Hermansen · clhermansen "at" gmail "dot" com

C'est ma façon de parler.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/algol68/attachments/20260212/058706f0/attachment.htm>


More information about the Algol68 mailing list