Discussion:
Awk program to uppercase Oberon keywords
(too old to reply)
n***@top-post
2004-11-14 15:25:25 UTC
Permalink
# Awk program to convert Oberon keywords that are in lowercase
# to uppercase. Handles nested comments.
# Caution: if you create identifiers that contain only lowercase
# letters and that are spelled the same as an Oberon keyword,
# they will be uppercased. (Obviously.)
Thanks. Now please someone quickly translate the code below to
Oberon or some other proper Algol-family language.

== Chris Glur
BEGIN {
quote = "\""
open_comment = "[(][*]"
close_comment = "[*][)]"
openers = quote "|" open_comment
sought = openers
setup_words()
}
## ----- Main loop. -----
{
while ( match( $0, sought ) )
{ Match( $0 )
$0 = RRIGHT
matched = RMATCH
process( RLEFT )
output( matched )
change_state( matched )
}
process( $0 )
output( "\n" )
}
## ----- Functions. -----
function change_state( s )
{
if ( s ~ open_comment )
{ in_comment++
sought = open_comment "|" close_comment
}
else if ( s ~ close_comment )
{ if ( --in_comment == 0 )
sought = openers
}
else if ( in_quote )
{ in_quote = 0
sought = openers
}
else
{ in_quote = 1
sought = quote
}
}
function process( s, accum )
{
accum = ""
if ( in_comment || in_quote )
accum = s
else
{
while ( match( s, /[a-zA-Z_]+/ ) )
{ Match( s )
if ( RMATCH in words )
RMATCH = toupper( RMATCH )
accum = accum RLEFT RMATCH
s = RRIGHT
}
accum = accum s
}
output( accum )
}
function output( s )
{ printf "%s", s
}
function setup_words( s,temp,i )
{
s = "array,begin,case,const,div,do,else,elsif,end,exit,if,import,in,is" \
",loop,mod,module,nil,of,or,pointer,procedure,record,repeat,return" \
",then,to,type,until,var,while,with,abs,ash,boolean,cap,char,chr,copy" \
",dec,entier,excl,false,halt,inc,incl,integer,len,long,longint" \
",longreal,max,min,new,odd,ord,real,set,short,shortint,size,true"
split( s, temp, /,/ )
for (i=1; i in temp; i++)
words[temp[i]] = 1
}
function Match( s )
{
if ( RSTART )
{ RMATCH = substr(s, RSTART, RLENGTH )
RLEFT = substr(s, 1, RSTART - 1)
RRIGHT = substr(s, RSTART + RLENGTH )
}
else
{ RMATCH = RLEFT = ""
RRIGHT = s
}
return RSTART
}
William James
2004-11-17 17:29:40 UTC
Permalink
Post by n***@top-post
Thanks. Now please someone quickly translate the code below to
Oberon or some other proper Algol-family language.
Why? It will work for you even if you hate Awk. Save the code in
a file named "ocase.awk" and run it with

awk -f ocase.awk prog.mo >prog.mod

I doubt that it can be quickly translated to Oberon. This sort of
thing is much easier in Awk.
John R. Strohm
2004-12-27 17:57:18 UTC
Permalink
Post by William James
Post by n***@top-post
Thanks. Now please someone quickly translate the code below to
Oberon or some other proper Algol-family language.
Why? It will work for you even if you hate Awk. Save the code in
a file named "ocase.awk" and run it with
awk -f ocase.awk prog.mo >prog.mod
I doubt that it can be quickly translated to Oberon. This sort of
thing is much easier in Awk.
And, given that this is a free-form procedural thing, it is probably even
easier, and less comprehensible, in PERL.

Or maybe TECO macros would be a reasonable way to go. I've done INCLUDE file
processors in AWK and TECO.

Or maybe SNOBOL. (Is there even anyone alive any more who actually knows
SNOBOL?)

Is there a version of AWK available that runs under Oberon?

----

Having flamed you enough for one day, I'll say this: I've used AWK a couple of
times, to do some fairly neat things. It was my primary language one year, when
I was writing a bunch of test plans and procedures: I had about five AWK scripts
that mechanized the step-numbering and the section extraction for our
documentation.

A couple of years later, I was again doing AWK scripts, this time to number the
steps and feed a WordPerfect macro that stuffed the test procedure into a
WordPerfect document.

The whole point of AWK, for me, was the built-in pattern matching: statements
are
pattern { actions }
not just
{ actions }
Lueko Willms
2004-12-27 19:35:00 UTC
Permalink
. On 27.12.04
wrote ***@airmail.net (John R. Strohm)
on /COMP/LANG/OBERON
in cqpifh$***@library1.airnews.net
about Re: Awk program to uppercase Oberon keywords


JRS> Or maybe SNOBOL. (Is there even anyone alive any more who actually
JRS> knows SNOBOL?)


Yes.

Not only the vendors of 'Spitbol', even I know at least a little
bit about SNOBOL.



Yours,
Lüko Willms http://www.willms-edv.de
/--------- ***@jpberlin.de -- Alle Rechte vorbehalten --

Ängstlich zu sinnen und zu denken, was man hätte tun können, ist das Übelste, was man tun _kann_. -G.C.Lichtenberg
Jürgen Kahrs
2004-12-28 11:53:55 UTC
Permalink
Post by John R. Strohm
And, given that this is a free-form procedural thing, it is probably even
easier, and less comprehensible, in PERL.
Or maybe TECO macros would be a reasonable way to go. I've done INCLUDE file
processors in AWK and TECO.
Or maybe SNOBOL. (Is there even anyone alive any more who actually knows
SNOBOL?)
You are free in the choice of language, of course.
But you should take into account that only one of
the languages you named is (by POSIX definition)
available on all Unix machines and almost every
other platform: AWK

Loading...