Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AWKCC source now available

1,239 views
Skip to first unread message

Aharon Robbins

unread,
Dec 16, 2011, 7:27:39 AM12/16/11
to
[ BCC to TUHS list, Brian Kernighan & Chris Ramming ]

awk 'BEGIN { print "Sherman, set the wayback machine for 1988" }'

Hello All.

This note is to announce that through the valiant efforts of Brian Kernighan,
Alcatel-Lucent has been persuaded to make the source for awkcc available.
It can be found at:

https://open-innovation.alcatel-lucent.com/projects/awkcc

You have to register (no cost) before being able to download, but
it's easy. The license terms are at the site. It's a straightforward
"for personal use" kind of license.

For those who don't know, awkcc is an adaptation of Unix awk to translate
nawk programs into C. It was originally implemented by Chris Ramming (then
at Bell Labs, although no longer) circa 1988, and the source dist includes
some doc that Chris wrote.

Given how fast machines are these days, this program is mostly of
historical interest. But it's nice to have this bit of Unix / awk history
generally available. And, if you really need to turn an awk program into
C, this may provide a starting point.

Enjoy!
--
Aharon (Arnold) Robbins arnold AT skeeve DOT com
P.O. Box 354 Home Phone: +972 8 979-0381
Nof Ayalon Cell Phone: +972 50 729-7545
D.N. Shimshon 99785 ISRAEL

Ed Morton

unread,
Dec 17, 2011, 12:48:44 PM12/17/11
to
On 12/16/2011 6:27 AM, Aharon Robbins wrote:
> [ BCC to TUHS list, Brian Kernighan& Chris Ramming ]
>
> awk 'BEGIN { print "Sherman, set the wayback machine for 1988" }'
>
> Hello All.
>
> This note is to announce that through the valiant efforts of Brian Kernighan,
> Alcatel-Lucent has been persuaded to make the source for awkcc available.
> It can be found at:
>
> https://open-innovation.alcatel-lucent.com/projects/awkcc
>
> You have to register (no cost) before being able to download, but
> it's easy. The license terms are at the site. It's a straightforward
> "for personal use" kind of license.
>
> For those who don't know, awkcc is an adaptation of Unix awk to translate
> nawk programs into C. It was originally implemented by Chris Ramming (then
> at Bell Labs, although no longer) circa 1988, and the source dist includes
> some doc that Chris wrote.
>
> Given how fast machines are these days, this program is mostly of
> historical interest. But it's nice to have this bit of Unix / awk history
> generally available. And, if you really need to turn an awk program into
> C, this may provide a starting point.
>
> Enjoy!

I did a fair bit of performance profiling involving awkcc in the late 90s since
I had a pre-processor for an Application-Oriented Language written in awk (nawk
actually) and our load building group wanted to speed up their overall build
time so they asked me if I could get the awk script to run any faster.

So I ran awkcc on the 700-line or so awk script and then compiled the resulting
C code. The result was that

a) the compiled C code didn't run noticeably faster than the interpreted awk
(YMMV vary on this I suppose), and
b) the generated C code, while functional, was not surprisingly difficult to
read and not structured the way I'd have structured a C program to do that job.

So I wouldn't use the C code generated by awkcc as a starting point for a C
program unless you don't plan to modify that segment of your code, just like you
wouldn't use the intermediate C code generated during compiling a C++ program as
a starting point for a C program.

Ed.

Janis Papanagnou

unread,
Dec 17, 2011, 2:46:40 PM12/17/11
to
Another awk to C compiler, awka (http://awka.sourceforge.net/elm.html) is
available on the net. The published performance numbers (I think they've
been comparing awka against nawk) show approximately a gain factor of ten
(and a smaller difference against gawk). So that tool might be an option
for those who like an awk->C pre-compilation. According to Andrew Sumner
it's not maintained any more, though.

Janis

scr...@gmail.com

unread,
May 20, 2014, 2:11:33 PM5/20/14
to
good, but the compilation failed on linux 64bits machine, see log:
make awkcc TYPE=ilinux CC=/usr/bin/gcc

rm -rf awkcc.zip include awkcc20/awkcc/awkcc \
awkcc20/awkcc/awkcc.sh awkcc20/lib/libAWK.a \
awkcc20/lib/*.o
mkdir -p include
cd awkcc20/lib; \
export CC; CC=; \
case ilinux in \
isolaris ) \
: use gnu yacc instead of /usr/ccs/bin/ to fix tests on isolaris; \
PATH="/opt/exp/gnu/bin:$PATH";; \
idarwin ) CC="gcc -m32 -D_FORTIFY_SOURCE=0";; \
darwin_gcc2 ) CC="gcc2";; \
cygwin_gcc2 ) CC="gcc-2";; \
hppa_gcc2 | isolaris_gcc2 ) CC=/opt/exp/old/bin/gcc;; \
esac; \
make -f makefile; \
cd ../awkcc; \
make -f makefile
make[1]: Entering directory `/usr/share/awkccsrc/awkcc20/lib'
/usr/bin/gcc -c -o misc.o misc.c
misc.c: In function ToStr:
misc.c:56: warning: incompatible implicit declaration of built-in function strcpy
misc.c: In function anas:
misc.c:67: warning: incompatible implicit declaration of built-in function strlen
misc.c:68: warning: incompatible implicit declaration of built-in function strcpy
misc.c: In function postmp:
misc.c:90: warning: incompatible implicit declaration of built-in function strcpy
misc.c: In function premp:
misc.c:110: warning: incompatible implicit declaration of built-in function strcpy
misc.c: In function vassign_str:
misc.c:175: warning: incompatible implicit declaration of built-in function strlen
misc.c:176: warning: incompatible implicit declaration of built-in function strcpy
misc.c: In function Atocase:
misc.c:193: warning: incompatible implicit declaration of built-in function strlen
misc.c: In function cat:
misc.c:216: warning: incompatible implicit declaration of built-in function strlen
misc.c: In function Asubstr:
misc.c:320: warning: incompatible implicit declaration of built-in function strlen
misc.c:335: warning: incompatible implicit declaration of built-in function strcpy
misc.c:340: warning: incompatible implicit declaration of built-in function strncpy
/usr/bin/gcc -c -o lines.o lines.c
lines.c: In function xgetl:
lines.c:19: warning: incompatible implicit declaration of built-in function strlen
lines.c: In function xfileget:
lines.c:53: warning: incompatible implicit declaration of built-in function strlen
/usr/bin/gcc -c -o gsub.o gsub.c
gsub.c: In function Agsub:
gsub.c:52: warning: incompatible implicit declaration of built-in function strlen
gsub.c:92: warning: incompatible implicit declaration of built-in function strcat
gsub.c: In function Arepsub:
gsub.c:115: warning: incompatible implicit declaration of built-in function strlen
gsub.c:125: warning: incompatible implicit declaration of built-in function strncat
gsub.c: In function Areplen:
gsub.c:139: warning: incompatible implicit declaration of built-in function strlen
/usr/bin/gcc -c -o xprintf.o xprintf.c
xprintf.c: In function xprintf:
xprintf.c:72: warning: incompatible implicit declaration of built-in function strlen
xprintf.c:85: warning: incompatible implicit declaration of built-in function strlen
xprintf.c:96: warning: incompatible implicit declaration of built-in function strlen
xprintf.c:105: warning: incompatible implicit declaration of built-in function strlen
/usr/bin/gcc -c -o awkrun.o awkrun.c
awkrun.c: In function doassign:
awkrun.c:222: warning: incompatible implicit declaration of built-in function strlen
awkrun.c: In function init_cmdline:
awkrun.c:383: warning: incompatible implicit declaration of built-in function strlen
awkrun.c:404: warning: incompatible implicit declaration of built-in function strlen
/usr/bin/gcc -c -o awkerr.o awkerr.c
/usr/bin/gcc -c -o comparisons.o comparisons.c
/usr/bin/gcc -c -o b.o b.c
In file included from b.c:19:
/usr/include/stdio.h:419: error: expected identifier or ( before if
b.c: In function mdfa:
b.c:128: warning: incompatible implicit declaration of built-in function calloc
b.c: In function minit:
b.c:153: warning: incompatible implicit declaration of built-in function free
b.c:154: warning: incompatible implicit declaration of built-in function calloc
b.c: In function penter:
b.c:184: warning: cast to pointer from integer of different size
b.c: In function freetr:
b.c:211: warning: incompatible implicit declaration of built-in function free
b.c:215: warning: incompatible implicit declaration of built-in function free
b.c:221: warning: incompatible implicit declaration of built-in function free
b.c: In function cclenter:
b.c:263: warning: incompatible implicit declaration of built-in function free
b.c: In function cfoll:
b.c:319: warning: cast from pointer to integer of different size
b.c:320: warning: cast from pointer to integer of different size
b.c:320: warning: cast from pointer to integer of different size
b.c:325: warning: incompatible implicit declaration of built-in function calloc
b.c:327: warning: cast from pointer to integer of different size
b.c: In function first:
b.c:354: warning: cast from pointer to integer of different size
b.c:355: warning: cast from pointer to integer of different size
b.c: In function pmatch:
b.c:481: warning: incompatible implicit declaration of built-in function free
b.c:483: warning: incompatible implicit declaration of built-in function calloc
b.c: In function nematch:
b.c:533: warning: incompatible implicit declaration of built-in function free
b.c:535: warning: incompatible implicit declaration of built-in function calloc
b.c: In function primary:
b.c:582: warning: cast to pointer from integer of different size
b.c: In function cgoto:
b.c:757: warning: cast to pointer from integer of different size
b.c:758: warning: cast to pointer from integer of different size
b.c:795: warning: incompatible implicit declaration of built-in function free
b.c:801: warning: incompatible implicit declaration of built-in function free
b.c:802: warning: incompatible implicit declaration of built-in function calloc
b.c: In function freefa:
b.c:826: warning: incompatible implicit declaration of built-in function free
b.c:828: warning: incompatible implicit declaration of built-in function free
b.c:831: warning: comparison between pointer and integer
b.c:831: warning: incompatible implicit declaration of built-in function free
b.c:831: warning: passing argument 1 of free makes pointer from integer without a cast
b.c:831: note: expected void * but argument is of type int
b.c:831: warning: assignment makes integer from pointer without a cast
b.c:834: warning: incompatible implicit declaration of built-in function free
b.c:835: warning: incompatible implicit declaration of built-in function free
make[1]: *** [b.o] Error 1
make[1]: Leaving directory `/usr/share/awkccsrc/awkcc20/lib'
make[1]: Entering directory `/usr/share/awkccsrc/awkcc20/awkcc'
/usr/bin/gcc -o awkcc awk.g.o awk.lx.o main.o getopt.o prefuncall.o comp.o print.o arrstack.o node.o walk.o write.o type.o symtab.o stack.o tempvar.o emitstmt.o emitfunc.o emitppmm.o misc.o fix.o printop.o emit.o
echo "CC=/usr/bin/gcc" > awkcc.sh
echo HEADERDIR=/opt/exp/lib/awkcc/include >> awkcc.sh
echo AWKLIB=/opt/exp/lib/awkcc/libAWK.a >> awkcc.sh
cat awkcc.sh.basic >> awkcc.sh
cp awkcc ../..
cp awkcc.sh ../..
make[1]: Leaving directory `/usr/share/awkccsrc/awkcc20/awkcc'

Abhay Gupta

unread,
May 22, 2014, 5:04:57 AM5/22/14
to
I want to write a single awk script to my problem. I dont know awk very well and I dont need it very much. I only need it for this problem. Please resolve the following problem (attached).\


* files are cateogrised as two columns

column1 column2
F1 F2
F3 F4
F5 F6
F7 F8
F9 F10
F11 F12
F13 F14
F15 F16
. .
. .
. .



Odd files(F1,F3....) have same patterns and even files(F2,F4,....) have another same pattern. For an example.

Odd file pattern: Even file pattern:
A1 10 C1 B1 05 D1
A2 20 C2 B2 12 D2
A1 03 C3 B3 23 D3
A1 54 C1 B2 13 D2
A3 23 C3 B1 14 D1
. . . . . .
. . . . . .

(Note: Number of lines for one field (in odd file) is equal to the number of lines for corresponding field (in corresponding even file). I know you donot understand it. I explain it clealy...
if there are 10 records(lines) in file1 (odd file) that starts from A1, then there are alos 10 records (lines) that starts from B1 in file2 (corresponding even file). but there position of occurence is not same i.e record starting from A1 and B1 may occur at different positions.

Now what I want to do is:-

Step1: Subtract the column 2 of record1 (line1) starting from A1 in file1 from the column 2 of line starting from B1 in file2. (i.e in above example 10-5=5, 03-14=-11 and so on....

Step:2 Add all the results (i.e 5+ (-11)+...........................)

Step3: Take the average (i.e 5+ (-11)+................/ (number of records having either A1 or B1 in file F1 or F2)

Step 4: Repeat Step 1,2 and 3 over all file pairs (F3,F4), (F5,F6), (F7,F8) and so on.

Step 5: Take the cumulative average=(average1+average2+average3+average4+................../total number of file pair)
here average i is the average of single file pair i calculated in step3.


with regards
Abhay












Abhay Gupta

unread,
May 22, 2014, 5:07:58 AM5/22/14
to
After a lot of trials I couldnot join this group. How can I join this group? .Sorry for posting my problem here.

Loki Harfagr

unread,
May 22, 2014, 8:24:54 AM5/22/14
to
Thu, 22 May 2014 02:07:58 -0700, Abhay Gupta did cat :

...
>> with regards
>>
>> Abhay
>
> After a lot of trials I couldnot join this group. How can I join this group? .Sorry for posting my problem here.


are you blonde?
"You're already on the other bank"

gan...@gmail.com

unread,
Jun 17, 2014, 8:34:30 AM6/17/14
to
Incorrect statement of the problem.
Some files may not contain elements of A1 or A2, or others. Therefore, the average for them is uncertain.

Janis Papanagnou

unread,
Jun 17, 2014, 10:50:34 AM6/17/14
to
On 17.06.2014 14:34, gan...@gmail.com wrote:
> Incorrect statement of the problem.
> Some files may not contain elements of A1 or A2, or others. Therefore, the average for them is uncertain.

Ganyush, to understand the problem I suggest reading either

http://volatile.gridbug.de/Essay.html [*]

or

http://cfaj.freeshell.org/google/

I hope at least one of those texts is enlightening.

Janis

[*] Source: http://eg.radioworldwide.org/

0 new messages