The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: dave@horsfall.org (Dave Horsfall)
Subject: [TUHS] Etymology of bc(1)
Date: Sat, 13 Sep 2014 06:02:26 +1000 (EST)	[thread overview]
Message-ID: <alpine.BSF.2.00.1409130539280.63870@aneurin.horsfall.org> (raw)
In-Reply-To: <1410529036.3893715.166731793.44CF06BA@webmail.messagingengine.com>

On Fri, 12 Sep 2014, random832 at fastmail.us wrote:

> What language does the undocumented option (assuming it is supported at 
> all) "bc -c" generate on FreeBSD and OSX? "Standard" bc, which actually 
> pipes to dc, generates (obviously) dc when run in this way, but GNU bc 
> generates a completely different and as far as I know undocumented 
> language, which is handled by the execute function (in execute.c) but as 
> far as I know there is no way to make it accept it on standard input.

According to my trusty Mac:

DIFFERENCES
    This version of bc was implemented from the POSIX P1003.2/D11 draft and
    contains several differences and extensions relative to the  draft  and
    traditional  implementations.  It is not implemented in the traditional
    way using dc(1).  This version is a single  process  which  parses  and
    runs  a  byte  code  translation  of the program.  There is an "undocu-
    mented" option (-c) that causes the program to output the byte code  to
    the  standard  output  instead  of  running it.  It was mainly used for
    debugging the parser and preparing the math library.

My trusty FreeBSD box says the same thing.  Well, they're both Gnu 1.06, 
after all, and it's some sort of byte-code.  I can sort see how it works; 
single digit integers, unless wrapped by "Knnn:" etc..

> Standard bc:
> $ echo '2+2' | bc -c
>  2 2+ps.
> q$
> 
> GNU bc:
> $ echo '2+2' | bc -c
> @iK2:K2:+W at r
> @i
> $

Oops; a "1" stands for itself, but other ints are bracketed:

davehorsmacbook:~ dave$ bc -c
@ibc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
1+1
11+W at r
@i2+2
K2:K2:+W at r
@i

Amusing that it treats "1" and "not 1" differently.  Oh, and "0" stands 
for itself.  One more test:

00+W at r
@i-1+1
1n1+W at r

So, that's something like "1 negate 1 add" - gasp, that's RPN!  I'd check 
the sources if I had them (none for Mac, and I didn't bother with FBSD).

-- Dave



  parent reply	other threads:[~2014-09-12 20:02 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-11 21:24 Christian Neukirchen
2014-09-11 21:41 ` Warner Losh
2014-09-11 22:04   ` Dave Horsfall
2014-09-11 22:17     ` John Cowan
2014-09-11 23:34       ` scj
2014-09-12  1:03       ` Dave Horsfall
2014-09-12 13:37         ` random832
2014-09-12 14:18           ` Steve Nickolas
2014-09-12 20:02           ` Dave Horsfall [this message]
2014-09-12  1:54 Noel Chiappa
2014-09-12  2:35 ` Mark Longridge
2014-09-12  6:00 ` Dave Horsfall
2014-09-12 11:15   ` John Cowan
2014-09-12 11:36     ` Otto Moerbeek
2014-09-12 17:12       ` scj
2014-09-12 17:18         ` Warner Losh
2014-09-12 19:02         ` Clem Cole
2014-09-12 19:36       ` Dave Horsfall
2014-09-12 20:03         ` Warner Losh
2014-09-12 19:32     ` Dave Horsfall
2014-09-12 18:28 ` Tim Bradshaw
2014-09-13  2:52   ` Dave Horsfall
2014-09-12  3:15 Noel Chiappa
2014-09-12  3:33 ` Larry McVoy
2014-09-12  6:10 ` Dave Horsfall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.BSF.2.00.1409130539280.63870@aneurin.horsfall.org \
    --to=dave@horsfall.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).