Originally reported via perlbug at https://rt.perl.org/Ticket/Display.html?id=31321
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.