How to resolve the algorithm Idiomatically determine all the characters that can be used for symbols step by step in the AWK programming language
How to resolve the algorithm Idiomatically determine all the characters that can be used for symbols step by step in the AWK programming language
Table of Contents
Problem Statement
Idiomatically determine all the characters that can be used for symbols. The word symbols is meant things like names of variables, procedures (i.e., named fragments of programs, functions, subroutines, routines), statement labels, events or conditions, and in general, anything a computer programmer can choose to name, but not being restricted to this list. Identifiers might be another name for symbols. The method should find the characters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other). Display the set of all the characters that can be used for symbols which can be used (allowed) by the computer program. You may want to mention what hardware architecture is being used, and if applicable, the operating system. Note that most languages have additional restrictions on what characters can't be used for the first character of a variable or statement label, for instance. These type of restrictions needn't be addressed here (but can be mentioned).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Idiomatically determine all the characters that can be used for symbols step by step in the AWK programming language
Source code in the awk programming language
# usage: gawk -f Idiomatically_determine_all_the_characters_that_can_be_used_for_symbols.awk
function is_valid_identifier(id, rc) {
fn = "is_valid_identifier.awk"
printf("function unused(%s) { arr[%s] = 1 }\n", id, 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 {
for (i = 0; i <= 255; i++) {
c = sprintf("%c", i)
if (is_valid_identifier(c))
good1 = good1 c;
else
bad1 = bad1 c
if (is_valid_identifier("_" c "_"))
good2 = good2 c;
else
bad2 = bad2 c;
}
printf("1st character: %d bad, %d ok: %s\n",
length(bad1), length(good1), good1)
printf("2nd..nth char: %d bad, %d ok: %s\n",
length(bad2), length(good2), good2)
exit(0)
}
You may also check:How to resolve the algorithm Phrase reversals step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Permutations step by step in the SAS programming language
You may also check:How to resolve the algorithm Plot coordinate pairs step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm Box the compass step by step in the Euphoria programming language