From: salomon@silver.cs.umanitoba.ca (Daniel J. Salomon)
Newsgroups: comp.lang.modula3
Subject: Re: why modula3?
Date: 7 Apr 92 20:56:53 GMT
Organization: Computer Science, University of Manitoba, Winnipeg, Canada

In article <1992Apr6.200515.22885@watdragon.waterloo.edu> twhlai@watdragon.waterloo.edu (Tony Lai) writes:
> Are uppercase keywords really so bad?  It is simple to write a program
> to convert one's favorite lowercase keywords to proper uppercase keywords.

I have written such a program, and included it with this posting.
It was not hard to write, but was rather tedious to type and test.

I wrote the original version because I had a problem with keywords in
Modula-2.  Although I prefer the appearance of uppercase keywords I
hate typing them in uppercase.  My solution was to write a filter that
would convert them to upper case.  I typically use it directly from vi
when editing a program (see below for more details).

Using this filter prevents you from using the reserved words in
lowercase as variables, but I don't think that that is a very safe
practice.   FOR for := from TO to DO do END;


#---- Remove this line and exerything before it. ----
#!/bin/csh
#
#   This shell script will generate the files:
#   m3uc.l, m3uc.flex, makefile.lex, and makefile.flex
#   The files contain both lex and flex source for a filter that
#   will read a Modula-3 source program and output it with all
#   the reserved keywords converted to uppercase.
#   Store this shell script in a file called bundle,
#   then to unbundle the files type:
#               sh bundle
#
#   If you have the scanner generator FLEX on your system, then
#   to compile the filter type the line:
#               make -f makefile.flex
#
#   If you do not have flex on your system, you can compile it using
#   lex by typing:
#               make -f makefile.lex
#
#   The program generated will be called "m3uc".
#   The program reads a Modula-3 program on standard input and
#   outputs it on standard output with all the keyword converted
#   to uppercase.
#   E.g.   m3uc  <mixed_case.m3 >upper_case.m3
#
#   The easiest way to use the filter is from inside vi.
#   To do so, move to the top of the file with the command: 1G
#   then pipe the whole program to the filter by typing: !G m3uc
#
sed -e s/X// <<==== >m3uc.l
X%{
X/*  		                       
X *  m3uc.l
X *  ======
X *  
X *  A lex script for a filter to convert Modula-3 keywords from
X *  mixed-case to uppercase.  Programs are easier to type if the
X *  keywords are entered in lowercase, but easier to read if the
X *  keywords are in uppercase.
X *  This filter gives you the best of both worlds.
X *
X *  The input is read from standard input, and the output generated
X *  on standard output.  Thus m3uc is easily used as a filter during
X *  a vi session.
X */
X
X    int comdep = 0;		/* Current comment nesting depth. */
X
X%}
X
X%Start  CODE COMMENT
X%a 5000
X%e 1500
X%k 1500
X%p 4000
X%o 7000
X
Xletter		[a-zA-Z]
Xdigit		[0-9]
Xa		[aA]
Xb		[bB]
Xc		[cC]
Xd		[dD]
Xe		[eE]
Xf		[fF]
Xg		[gG]
Xh		[hH]
Xi		[iI]
Xj		[jJ]
Xk		[kK]
Xl		[lL]
Xm		[mM]
Xn		[nN]
Xo		[oO]
Xp		[pP]
Xq		[qQ]
Xr		[rR]
Xs		[sS]
Xt		[tT]
Xu		[uU]
Xv		[vV]
Xw		[wW]
Xx		[xX]
Xy		[yY]
Xz		[zZ]
X
X%%
X
X			BEGIN CODE; /* Enter scanner in CODE state. */
X
X<CODE>"(*"		{ ECHO;  BEGIN COMMENT;  comdep++; }
X<COMMENT>"(*"		{ ECHO;  comdep++; }
X<COMMENT>"*)"		{
X			    ECHO;
X			    comdep--;
X			    if (comdep<1) BEGIN CODE;
X			}
X<COMMENT>.		ECHO;
X<COMMENT>\n		ECHO;
X<CODE>"*)"		{
X			    ECHO;
X			    fprintf (stderr,
X				"\n(**** Unopened comment. ****)\n");
X			}
X<CODE>{a}{b}{s}			printf ("ABS");
X<CODE>{a}{d}{d}{r}{e}{s}{s}	printf ("ADDRESS");
X<CODE>{a}{d}{r}			printf ("ADR");
X<CODE>{a}{d}{r}{s}{i}{z}{e}	printf ("ADRSIZE");
X<CODE>{a}{n}{d}			printf ("AND");
X<CODE>{a}{n}{y}			printf ("ANY");
X<CODE>{a}{r}{r}{a}{y}		printf ("ARRAY");
X<CODE>{a}{s}			printf ("AS");
X<CODE>{b}{e}{g}{i}{n}		printf ("BEGIN");
X<CODE>{b}{i}{t}{s}		printf ("BITS");
X<CODE>{b}{i}{t}{s}{i}{z}{e}	printf ("BITSIZE");
X<CODE>{b}{o}{o}{l}{e}{a}{n}	printf ("BOOLEAN");
X<CODE>{b}{r}{a}{n}{d}{e}{d}	printf ("BRANDED");
X<CODE>{b}{y}			printf ("BY");
X<CODE>{b}{y}{t}{e}{s}{i}{z}{e}	printf ("BYTESIZE");
X<CODE>{c}{a}{r}{d}{i}{n}{a}{l}	printf ("CARDINAL");
X<CODE>{c}{a}{s}{e}		printf ("CASE");
X<CODE>{c}{e}{i}{l}{i}{n}{g}	printf ("CEILING");
X<CODE>{c}{h}{a}{r}		printf ("CHAR");
X<CODE>{c}{o}{n}{s}{t}		printf ("CONST");
X<CODE>{d}{e}{c}			printf ("DEC");
X<CODE>{d}{i}{s}{p}{o}{s}{e}	printf ("DISPOSE");
X<CODE>{d}{i}{v}			printf ("DIV");
X<CODE>{d}{o}			printf ("DO");
X<CODE>{e}{l}{s}{e}		printf ("ELSE");
X<CODE>{e}{l}{s}{i}{f}		printf ("ELSIF");
X<CODE>{e}{n}{d}			printf ("END");
X<CODE>{e}{v}{a}{l}		printf ("EVAL");
X<CODE>{e}{x}{c}{e}{p}{t}	printf ("EXCEPT");
X<CODE>{e}{x}{c}{e}{p}{t}{i}{o}{n}	printf ("EXCEPTION");
X<CODE>{e}{x}{i}{t}		printf ("EXIT");
X<CODE>{e}{x}{p}{o}{r}{t}{s}	printf ("EXPORTS");
X<CODE>{e}{x}{t}{e}{n}{d}{e}{d}	printf ("EXTENDED");
X<CODE>{f}{a}{l}{s}{e}		printf ("FALSE");
X<CODE>{f}{i}{n}{a}{l}{l}{y}	printf ("FINALLY");
X<CODE>{f}{i}{r}{s}{t}		printf ("FIRST");
X<CODE>{f}{l}{o}{a}{t}		printf ("FLOAT");
X<CODE>{f}{l}{o}{o}{r}		printf ("FLOOR");
X<CODE>{f}{o}{r}			printf ("FOR");
X<CODE>{f}{r}{o}{m}		printf ("FROM");
X<CODE>{i}{f}			printf ("IF");
X<CODE>{i}{m}{p}{o}{r}{t}	printf ("IMPORT");
X<CODE>{i}{n}			printf ("IN");
X<CODE>{i}{n}{c}			printf ("INC");
X<CODE>{i}{n}{t}{e}{g}{e}{r}	printf ("INTEGER");
X<CODE>{i}{n}{t}{e}{r}{f}{a}{c}{e}	printf ("INTERFACE");
X<CODE>{i}{s}{t}{y}{p}{e}	printf ("ISTYPE");
X<CODE>{l}{a}{s}{t}		printf ("LAST");
X<CODE>{l}{o}{c}{k}		printf ("LOCK");
X<CODE>{l}{o}{n}{g}{r}{e}{a}{l}	printf ("LONGREAL");
X<CODE>{l}{o}{o}{p}		printf ("LOOP");
X<CODE>{l}{o}{o}{p}{h}{o}{l}{e}	printf ("LOOPHOLE");
X<CODE>{m}{a}{x}			printf ("MAX");
X<CODE>{m}{e}{t}{h}{o}{d}{s}	printf ("METHODS");
X<CODE>{m}{i}{n}			printf ("MIN");
X<CODE>{m}{o}{d}			printf ("MOD");
X<CODE>{m}{o}{d}{u}{l}{e}	printf ("MODULE");
X<CODE>{m}{u}{t}{e}{x}		printf ("MUTEX");
X<CODE>{n}{a}{r}{r}{o}{w}	printf ("NARROW");
X<CODE>{n}{e}{w}			printf ("NEW");
X<CODE>{n}{i}{l}			printf ("NIL");
X<CODE>{n}{o}{t}			printf ("NOT");
X<CODE>{n}{u}{l}{l}		printf ("NULL");
X<CODE>{n}{u}{m}{b}{e}{r}	printf ("NUMBER");
X<CODE>{o}{b}{j}{e}{c}{t}	printf ("OBJECT");
X<CODE>{o}{f}			printf ("OF");
X<CODE>{o}{r}			printf ("OR");
X<CODE>{o}{r}{d}			printf ("ORD");
X<CODE>{o}{v}{e}{r}{r}{i}{d}{e}	printf ("OVERRIDE");
X<CODE>{p}{r}{o}{c}{e}{d}{u}{r}{e} printf ("PROCEDURE");
X<CODE>{r}{a}{i}{s}{e}		printf ("RAISE");
X<CODE>{r}{a}{i}{s}{e}{s}	printf ("RAISES");
X<CODE>{r}{e}{a}{d}{o}{n}{l}{y}	printf ("READONLY");
X<CODE>{r}{e}{a}{l}		printf ("REAL");
X<CODE>{r}{e}{c}{o}{r}{d}	printf ("RECORD");
X<CODE>{r}{e}{f}			printf ("REF");
X<CODE>{r}{e}{f}{a}{n}{y}	printf ("REFANY");
X<CODE>{r}{e}{p}{e}{a}{t}	printf ("REPEAT");
X<CODE>{r}{e}{t}{u}{r}{n}	printf ("RETURN");
X<CODE>{r}{e}{v}{e}{a}{l}	printf ("REVEAL");
X<CODE>{r}{o}{o}{t}		printf ("ROOT");
X<CODE>{r}{o}{u}{n}{d}		printf ("ROUND");
X<CODE>{s}{e}{t}			printf ("SET");
X<CODE>{s}{u}{b}{a}{r}{r}{a}{y}	printf ("SUBARRAY");
X<CODE>{t}{e}{x}{t}		printf ("TEXT");
X<CODE>{t}{h}{e}{n}		printf ("THEN");
X<CODE>{t}{o}			printf ("TO");
X<CODE>{t}{r}{u}{e}		printf ("TRUE");
X<CODE>{t}{r}{u}{n}{c}		printf ("TRUNC");
X<CODE>{t}{r}{y}			printf ("TRY");
X<CODE>{t}{y}{p}{e}		printf ("TYPE");
X<CODE>{t}{y}{p}{e}{c}{a}{s}{e}	printf ("TYPECASE");
X<CODE>{t}{y}{p}{e}{c}{o}{d}{e}	printf ("TYPECODE");
X<CODE>{u}{n}{s}{a}{f}{e}	printf ("UNSAFE");
X<CODE>{u}{n}{t}{i}{l}		printf ("UNTIL");
X<CODE>{u}{n}{t}{r}{a}{c}{e}{d}	printf ("UNTRACED");
X<CODE>{v}{a}{l}			printf ("VAL");
X<CODE>{v}{a}{l}{u}{e}		printf ("VALUE");
X<CODE>{v}{a}{r}			printf ("VAR");
X<CODE>{w}{h}{i}{l}{e}		printf ("WHILE");
X<CODE>{w}{i}{t}{h}		printf ("WITH");
X
X<CODE>{letter}({letter}|{digit}|"_")*	ECHO;	/* Identifiers. */
X<CODE>\"([^\"\n])+\"	ECHO;	/* Quote delimited strings. */
X<CODE>\n		ECHO;
X<CODE>.		ECHO;	/* All other characters. */
X%%
====
sed -e s/X// <<==== >m3uc.flex
X%{
X/*  		                       
X *  m3uc.flex
X *  =========
X *  
X *  A flex script for a filter to convert Modula-3 keywords from
X *  mixed-case to uppercase.  This version takes advantage of flex's
X *  special feature for case insensitivity.  Programs are easier to
X *  type if the keywords are entered in lowercase, but easier to
X *  read if the keywords are in uppercase.
X *  This filter gives you the best of both worlds.
X *
X *  The input is read from standard input, and the output generated
X *  on standard output.  Thus m3uc is easily used as a filter during
X *  a vi session.
X */
X
X    int comdep = 0;		/* Current comment nesting depth. */
X
X%}
X
X%Start  CODE COMMENT
X
Xletter		[a-zA-Z]
Xdigit		[0-9]
X
X%%
X
X			BEGIN CODE; /* Enter scanner in CODE state. */
X
X<CODE>"(*"		{ ECHO;  BEGIN COMMENT;  comdep++; }
X<COMMENT>"(*"		{ ECHO;  comdep++; }
X<COMMENT>"*)"		{
X			    ECHO;
X			    comdep--;
X			    if (comdep<1) BEGIN CODE;
X			}
X<COMMENT>.		ECHO;
X<COMMENT>\n		ECHO;
X<CODE>"*)"		{
X			    ECHO;
X			    fprintf (stderr,
X				"\n(**** Unopened comment. ****)\n");
X			}
X<CODE>abs		printf ("ABS");
X<CODE>address		printf ("ADDRESS");
X<CODE>adr		printf ("ADR");
X<CODE>adrsize		printf ("ADRSIZE");
X<CODE>and		printf ("AND");
X<CODE>any		printf ("ANY");
X<CODE>array		printf ("ARRAY");
X<CODE>as		printf ("AS");
X<CODE>begin		printf ("BEGIN");
X<CODE>bits		printf ("BITS");
X<CODE>bitsize		printf ("BITSIZE");
X<CODE>boolean		printf ("BOOLEAN");
X<CODE>branded		printf ("BRANDED");
X<CODE>by		printf ("BY");
X<CODE>bytesize		printf ("BYTESIZE");
X<CODE>cardinal		printf ("CARDINAL");
X<CODE>case		printf ("CASE");
X<CODE>ceiling		printf ("CEILING");
X<CODE>char		printf ("CHAR");
X<CODE>const		printf ("CONST");
X<CODE>dec		printf ("DEC");
X<CODE>dispose		printf ("DISPOSE");
X<CODE>div		printf ("DIV");
X<CODE>do		printf ("DO");
X<CODE>else		printf ("ELSE");
X<CODE>elsif		printf ("ELSIF");
X<CODE>end		printf ("END");
X<CODE>eval		printf ("EVAL");
X<CODE>except		printf ("EXCEPT");
X<CODE>exception		printf ("EXCEPTION");
X<CODE>exit		printf ("EXIT");
X<CODE>exports		printf ("EXPORTS");
X<CODE>extended		printf ("EXTENDED");
X<CODE>false		printf ("FALSE");
X<CODE>finally		printf ("FINALLY");
X<CODE>first		printf ("FIRST");
X<CODE>float		printf ("FLOAT");
X<CODE>floor		printf ("FLOOR");
X<CODE>for		printf ("FOR");
X<CODE>from		printf ("FROM");
X<CODE>if		printf ("IF");
X<CODE>import		printf ("IMPORT");
X<CODE>in		printf ("IN");
X<CODE>inc		printf ("INC");
X<CODE>integer		printf ("INTEGER");
X<CODE>interface		printf ("INTERFACE");
X<CODE>istype		printf ("ISTYPE");
X<CODE>last		printf ("LAST");
X<CODE>lock		printf ("LOCK");
X<CODE>longreal		printf ("LONGREAL");
X<CODE>loop		printf ("LOOP");
X<CODE>loophole		printf ("LOOPHOLE");
X<CODE>max		printf ("MAX");
X<CODE>methods		printf ("METHODS");
X<CODE>min		printf ("MIN");
X<CODE>mod		printf ("MOD");
X<CODE>module		printf ("MODULE");
X<CODE>mutex		printf ("MUTEX");
X<CODE>narrow		printf ("NARROW");
X<CODE>new		printf ("NEW");
X<CODE>nil		printf ("NIL");
X<CODE>not		printf ("NOT");
X<CODE>null		printf ("NULL");
X<CODE>number		printf ("NUMBER");
X<CODE>object		printf ("OBJECT");
X<CODE>of		printf ("OF");
X<CODE>or		printf ("OR");
X<CODE>ord		printf ("ORD");
X<CODE>override		printf ("OVERRIDE");
X<CODE>procedure		printf ("PROCEDURE");
X<CODE>raise		printf ("RAISE");
X<CODE>raises		printf ("RAISES");
X<CODE>readonly		printf ("READONLY");
X<CODE>real		printf ("REAL");
X<CODE>record		printf ("RECORD");
X<CODE>ref		printf ("REF");
X<CODE>refany		printf ("REFANY");
X<CODE>repeat		printf ("REPEAT");
X<CODE>return		printf ("RETURN");
X<CODE>reveal		printf ("REVEAL");
X<CODE>root		printf ("ROOT");
X<CODE>round		printf ("ROUND");
X<CODE>set		printf ("SET");
X<CODE>subarray		printf ("SUBARRAY");
X<CODE>text		printf ("TEXT");
X<CODE>then		printf ("THEN");
X<CODE>to		printf ("TO");
X<CODE>true		printf ("TRUE");
X<CODE>trunc		printf ("TRUNC");
X<CODE>try		printf ("TRY");
X<CODE>type		printf ("TYPE");
X<CODE>typecase		printf ("TYPECASE");
X<CODE>typecode		printf ("TYPECODE");
X<CODE>unsafe		printf ("UNSAFE");
X<CODE>until		printf ("UNTIL");
X<CODE>untraced		printf ("UNTRACED");
X<CODE>val		printf ("VAL");
X<CODE>value		printf ("VALUE");
X<CODE>var		printf ("VAR");
X<CODE>while		printf ("WHILE");
X<CODE>with		printf ("WITH");
X
X<CODE>{letter}({letter}|{digit}|"_")*	ECHO;	/* Identifiers. */
X<CODE>\"([^\"\n])+\"	ECHO;	/* Quote delimited strings. */
X<CODE>\n		ECHO;
X<CODE>.		ECHO;	/* All other characters. */
X%%
====
sed -e s/X// <<==== >makefile.lex
X#  makefile.lex  - LEX version
X#  ============
X#
X#  Generate m3uc using LEX.
X#
X
Xm3uc: m3uc.c
X	cc -O m3uc.c -ll -o m3uc
X
Xm3uc.c: m3uc.l
X	lex m3uc.l
X	mv lex.yy.c m3uc.c
====
sed -e s/X// <<==== >makefile.flex
X#  makefile.flex  - FLEX version
X#  =============
X#
X#  Generate m3uc using FLEX.
X#
X
Xm3uc: m3uc.c
X	cc -O m3uc.c -ll -o m3uc
X
Xm3uc.c: m3uc.flex
X	flex -i m3uc.flex
X	mv lex.yy.c m3uc.c
====
Newsgroups: comp.lang.modula3