Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a2p fails to parse valid do-while loop in awk script #7477

Closed
p5pRT opened this issue Aug 25, 2004 · 7 comments
Closed

a2p fails to parse valid do-while loop in awk script #7477

p5pRT opened this issue Aug 25, 2004 · 7 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Aug 25, 2004

Migrated from rt.perl.org#31321 (status was 'rejected')

Searchable as RT31321$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 25, 2004

From keith@batky-howell.com

a2p fails to translate valid awk syntax, saying "syntax error".
Example input to demonstrate the problem​:

BEGIN{ do{ print a++
  } while(a<2)
  exit(0); }

If I call this "tmp.awk" and run "a2p tmp.awk", I get this output​:
  syntax error in file tmp.awk at line 2
  Translation aborted due to syntax errors.
The line in error is the while(condition) after the closing "}".

A similar, but different failure (probably deserving of a
separate defect report) is a2p's failure to correctly parse
complex boolean arithmetic. Consider the following, which
encapsulates a few lines from a working "battleship" game
written in AWK​:

function should_work(r,c,shot){
  # excerpt taken from a battle ship game (HIT_AND_SUNK="#" or some such)
  l= (r>0)*((shot[r-1,c]=="")-(shot[r-1,c]==HIT_AND_SUNK))
  l+=(r<9)*((shot[r+1,c]=="")-(shot[r+1,c]==HIT_AND_SUNK))
  l+=(c>0)*((shot[r,c-1]=="")-(shot[r,c-1]==HIT_AND_SUNK))
  l+=(c<9)*((shot[r,c+1]=="")-(shot[r,c+1]==HIT_AND_SUNK))
  return l
}
BEGIN{ HIT_AND_SUNK="#"; print should_work(3,6,empty); exit(0); }

If I put this into tmp2.awk and run "a2p tmp2.awk", I get this​:
syntax error in file tmp2.awk at line 3
Translation aborted due to syntax errors.

Both of these examples not only are parsed correctly by AWK,
but actually work as expected.

Thank you for any consideration of this matter. My situation is
that I am about to teach a 5-day perl class, and wanted to try
translating some entertaining AWK scripts to see what came out,
but a2p appears to only work on the simplest, shortest, awk scripts.
I'm wondering if perhaps it's even worth the trouble to fix these
issues, but then, if we can't use a2p, what is the alternative?
You may contact me as user "keith" at the "batky-howell.com"
domain or as user "keith.blackwell" at the "jymis.com" domain,
but please do not allow my email addresses to be posted in any
fashion to the web. Thank you again.

Perl Info

Flags:
    category=utilities
    severity=high

Site configuration information for perl v5.8.1:

Configured by bhcompile at Wed Oct 15 10:50:03 EDT 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.4.21-2.elsmp, archname=i386-linux-thread-multi
    uname='linux daffy.perf.redhat.com 2.4.21-2.elsmp #1 smp wed sep 17 15:00:55 edt 2003 i686 i686 i386 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -march=i386 -mcpu=i686 -Dversion=5.8.1 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Dotherlibdirs=/usr/lib/perl5/5.8.1 -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dinc_version_list=5.8.0/i386-linux-thread-multi 5.8.0 -Dpager=/usr/bin/less -isr'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -g -pipe -march=i386 -mcpu=i686',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.3.1 20030930 (Red Hat Linux 3.3.1-6)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.1/i386-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.8.1:
    /usr/lib/perl5/5.8.1/i386-linux-thread-multi
    /usr/lib/perl5/5.8.1
    /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.1
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.1
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.8.1/i386-linux-thread-multi
    /usr/lib/perl5/5.8.1
    .


Environment for perl v5.8.1:
    HOME=/home/keith
    LANG=en_US
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/opt/j2sdk_nb/j2sdk1.4.2/bin:/opt/oracle/product/8.1.7/bin:/home/keith/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 29, 2004

From @rgs

keith (via RT) wrote​:

a2p fails to translate valid awk syntax, saying "syntax error".

I think that a2p comes from the good old days of awk, before it evolves
into nawk and gawk. I'm not surprised limitations are found in it. Which
awk are you using ?

Thank you for any consideration of this matter. My situation is
that I am about to teach a 5-day perl class, and wanted to try
translating some entertaining AWK scripts to see what came out,

gee, there are still people who learn awk (and sed, I assume) before
perl :)

but a2p appears to only work on the simplest, shortest, awk scripts.
I'm wondering if perhaps it's even worth the trouble to fix these
issues, but then, if we can't use a2p, what is the alternative?

Silly idea​: find a small group of CS students and make them work, as a
project, on improving a2p. Note to self​: I might even do this myself.

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 29, 2004

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 31, 2004

From keith@batky-howell.com

Rafael Garcia-Suarez <rgarciasuarez@​mandrakesoft.com> wrote​:
| keith (via RT) wrote​:
| > a2p fails to translate valid awk syntax, saying "syntax error".
|
| I think that a2p comes from the good old days of awk, before it evolves
| into nawk and gawk. I'm not surprised limitations are found in it. Which
| awk are you using ?

I've used both gawk on linux and "nawk" (now just called "awk") on an SCO
and HPUX system. I imagine I've probably just scratched the surface of
a2p's limitations in this respect.

| gee, there are still people who learn awk (and sed, I assume) before
| perl :)

I was an AWK hacker since the days when Larry Wall was known for "patch"
instead of "perl". :-) Believe it or not, some of our student-clients *do*
want to know AWK, but mainly for one-liners and such. They might change
their mind once we show them what Perl can do, of course, but some of
the folks wanting to learn AWK already know Perl!

| Silly idea​: find a small group of CS students and make them work, as a
| project, on improving a2p. Note to self​: I might even do this myself.

Heh heh, that's what graduate students are for. But even though I'm
in the field of "education" now, it's corporate-level technical
instruction, not an academic insitution, so I don't have access to such
free labor. If anyone wants to fix this, it could be useful for
extending the life of complex AWK scripts (of which I have several),
but it's not a real pressing need. I suppose that's true for almost
everyone else (not an urgent need). So I don't have much hope of this
getting fixed. Still, if you do it, let me know! :-)

--
Keith W Blackwell

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jan 16, 2018

From zefram@fysh.org

a2p is no longer part of the Perl core distro, so this ticket should
be closed. a2p is now maintained as a CPAN distro App-a2p; this bug
could be sensibly re-reported to its bug queue at rt.cpan.org.

-zefram

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jan 16, 2018

From @tonycoz

On Tue, 16 Jan 2018 14​:06​:06 -0800, zefram@​fysh.org wrote​:

a2p is no longer part of the Perl core distro, so this ticket should
be closed. a2p is now maintained as a CPAN distro App-a2p; this bug
could be sensibly re-reported to its bug queue at rt.cpan.org.

-zefram

https://rt.cpan.org/Ticket/Display.html?id=124108

Closing.

Tony

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jan 16, 2018

@tonycoz - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant