Idiomatically determine all the characters that can be used for symbols: Difference between revisions

→‎{{header|AWK}}: Clean up code to not include special rules for whitespace; also, AWK is not uppercase letter only
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
(→‎{{header|AWK}}: Clean up code to not include special rules for whitespace; also, AWK is not uppercase letter only)
Line 17:
 
=={{header|AWK}}==
<lang AWK># usage: gawk -f Idiomatically_determine_all_the_characters_that_can_be_used_for_symbols.awk
<lang AWK>
 
# syntax: GAWK -f IDIOMATICALLY_DETERMINE_ALL_THE_CHARACTERS_THAT_CAN_BE_USED_FOR_SYMBOLS.AWK
function runis_valid_identifier(cid, rc) {
fn = "is_valid_identifier.awk"
printf("BEGIN{function unused(%s+=0) {}\n",c id, id) >fn
printf("BEGIN { exit(0) }\n") >>fn
close(fn)
 
rc = system("gawk -f is_valid_identifier.awk 2>errors")
return( rc) == 0
 
BEGIN {
fnfor (i = "TEMP.AWK"0; i <= 255; i++) {
cmd c = sprintf("GAWK -f %s 2>NULc",fn i)
 
for (i=0; i<=255; i++) {
c = sprintfif (is_valid_identifier("%c",i))
good1 = good1 c;
if (c ~ /\x09|\x0D|\x0A|\x20/) { ng++; continue } # tab,CR,LF,space
else
(run(c) == 0) ? (ok1 = ok1 c) : (ng1 = ng1 c) # 1st character
(run("_" c) == 0) ? (ok2 = ok2 c) : (ng2bad1 = ng2bad1 c) # 2nd..nth character
 
if (is_valid_identifier("_" c "_"))
good2 = good2 c;
else
bad2 = bad2 c;
}
 
printf("1st character: %d NG, %d OK %s\n",length(ng1)+ng,length(ok1),ok1)
printf("2nd..nth1st charcharacter: %d NGbad, %d OKok: %s\n",length(ng2)+ng,length(ok2),ok2)
length(bad1), length(good1), good1)
printf("2nd..nth char: %d bad, %d ok: %s\n",
length(bad2), length(good2), good2)
exit(0)
function run(c, rc) {
printf("BEGIN{%s+=0}\n",c) >fn
close(fn)
rc = system(cmd)
return(rc)
}
</lang>
<p>output:</p>
<pre>
1st character: 203 NGbad, 53 OKok: ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
2nd..nth char: 193 NGbad, 63 OKok: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
</pre>