🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4289

Re: Need filter to raise keywords to uppercase

#4289
From: fred sullivan
Date: Sat, 18 Jun 1988 22:51
132 lines
4858 bytes
In article <898@acornrc.UUCP> bob@acornrc.UUCP (Bob Weissman) writes:
>Does anyone have a filter which will raise all Modula-2 keywords to
>uppercase?  I've just acquired a bunch of code which was obviously
>meant for some bizarre compiler which accepts keywords in lowercase.
>
Here is a lex filter.  I thought someone else might be interested so
I'm posting it.  (If you're not using a Unix system you're out of
luck, but that goes without saying.)  Run it through lex to produce
lex.yy.c, and compile with -ll.  Any word which is the same as a reserved
word except for case is changed to uppercase, except for words appearing
in strings or comments (nested comments are ok).  E.g. "tYPe" becomes
"TYPE".  I usually use this to filter the buffer in Emacs.

-- cut here --
a	[aA]
b	[bB]
c	[cC]
d	[dD]
e	[eE]
f	[fF]
g	[gG]
h	[hH]
i	[iI]
j	[jJ]
k	[kK]
l	[lL]
m	[mM]
n	[nN]
o	[oO]
p	[pP]
q	[qQ]
r	[rR]
s	[sS]
t	[tT]
u	[uU]
v	[vV]
w	[wW]
x	[xX]
y	[yY]
z	[zZ]

 int commentlevel;

%START OTHER COMMENT STRING DSTRING
%a 2200
%o 2500
%%
<OTHER>{a}{b}{s}			printf("ABS");
<OTHER>{a}{n}{d}			printf("AND");
<OTHER>{a}{r}{r}{a}{y}			printf("ARRAY");
<OTHER>{b}{e}{g}{i}{n}			printf("BEGIN");
<OTHER>{b}{i}{t}{s}{e}{t}		printf("BITSET");
<OTHER>{b}{o}{o}{l}{e}{a}{n}		printf("BOOLEAN");
<OTHER>{b}{y}				printf("BY");
<OTHER>{c}{a}{p}			printf("CAP");
<OTHER>{c}{a}{r}{d}{i}{n}{a}{l}		printf("CARDINAL");
<OTHER>{c}{a}{s}{e}			printf("CASE");
<OTHER>{c}{h}{a}{r}			printf("CHAR");
<OTHER>{c}{h}{r}			printf("CHR");
<OTHER>{c}{o}{n}{s}{t}			printf("CONST");
<OTHER>{d}{e}{c}			printf("DEC");
<OTHER>{d}{e}{f}{i}{n}{i}{t}{i}{o}{n}	printf("DEFINITION");
<OTHER>{d}{i}{s}{p}{o}{s}{e}		printf("DISPOSE");
<OTHER>{d}{i}{v}			printf("DIV");
<OTHER>{d}{o}				printf("DO");
<OTHER>{e}{l}{s}{e}			printf("ELSE");
<OTHER>{e}{l}{s}{i}{f}			printf("ELSIF");
<OTHER>{e}{n}{d}			printf("END");
<OTHER>{e}{x}{c}{l}			printf("EXCL");
<OTHER>{e}{x}{i}{t}			printf("EXIT");
<OTHER>{e}{x}{p}{o}{r}{t}		printf("EXPORT");
<OTHER>{f}{a}{l}{s}{e}			printf("FALSE");
<OTHER>{f}{l}{o}{a}{t}			printf("FLOAT");
<OTHER>{f}{o}{r}			printf("FOR");
<OTHER>{f}{r}{o}{m}			printf("FROM");
<OTHER>{h}{a}{l}{t}			printf("HALT");
<OTHER>{h}{i}{g}{h}			printf("HIGH");
<OTHER>{i}{f}				printf("IF");
<OTHER>{i}{m}{p}{l}{e}{m}{e}{n}{t}{a}{t}{i}{o}{n}  printf("IMPLEMENTATION");
<OTHER>{i}{m}{p}{o}{r}{t}		printf("IMPORT");
<OTHER>{i}{n}				printf("IN");
<OTHER>{i}{n}{c}			printf("INC");
<OTHER>{i}{n}{c}{l}			printf("INCL");
<OTHER>{i}{n}{t}{e}{g}{e}{r}		printf("INTEGER");
<OTHER>{l}{o}{o}{p}			printf("LOOP");
<OTHER>{m}{o}{d}			printf("MOD");
<OTHER>{m}{o}{d}{u}{l}{e}		printf("MODULE");
<OTHER>{n}{e}{w}			printf("NEW");
<OTHER>{n}{i}{l}			printf("NIL");
<OTHER>{n}{o}{t}			printf("NOT");
<OTHER>{o}{d}{d}			printf("ODD");
<OTHER>{o}{f}				printf("OF");
<OTHER>{o}{r}				printf("OR");
<OTHER>{o}{r}{d}			printf("ORD");
<OTHER>{p}{o}{i}{n}{t}{e}{r}		printf("POINTER");
<OTHER>{p}{r}{o}{c}			printf("PROC");
<OTHER>{p}{r}{o}{c}{e}{d}{u}{r}{e}	printf("PROCEDURE");
<OTHER>{q}{u}{a}{l}{i}{f}{i}{e}{d}	printf("QUALIFIED");
<OTHER>{r}{e}{a}{l}			printf("REAL");
<OTHER>{r}{e}{c}{o}{r}{d}		printf("RECORD");
<OTHER>{r}{e}{p}{e}{a}{t}		printf("REPEAT");
<OTHER>{r}{e}{t}{u}{r}{n}		printf("RETURN");
<OTHER>{s}{e}{t}			printf("SET");
<OTHER>{t}{h}{e}{n}			printf("THEN");
<OTHER>{t}{o}				printf("TO");
<OTHER>{t}{r}{u}{e}			printf("TRUE");
<OTHER>{t}{r}{u}{n}{c}			printf("TRUNC");
<OTHER>{t}{y}{p}{e}			printf("TYPE");
<OTHER>{u}{n}{t}{i}{l}			printf("UNTIL");
<OTHER>{v}{a}{l}			printf("VAL");
<OTHER>{v}{a}{r}			printf("VAR");
<OTHER>{w}{h}{i}{l}{e}			printf("WHILE");
<OTHER>{w}{i}{t}{h}			printf("WITH");
<OTHER>[a-zA-Z][a-zA-Z0-9]*		ECHO;
<OTHER>\(\*		{ ECHO; commentlevel = 1; BEGIN COMMENT; }
<COMMENT>\*\)		{ ECHO; if (--commentlevel == 0) BEGIN OTHER; }
<COMMENT>\(\*		{ ECHO; ++commentlevel; }
<OTHER>\"		{ ECHO; BEGIN DSTRING; }
<DSTRING>\"		{ ECHO; BEGIN OTHER; }
<OTHER>\'		{ ECHO; BEGIN STRING; }
<STRING>\'		{ ECHO; BEGIN OTHER; }
%%
main()
{
  BEGIN OTHER;
  while (yylex());
}
-- all done --
Fred Sullivan				SUNY at Binghamton
Dept. Math. Sciences			Binghamton, NY 13903
					sullivan@marge.math.binghamton.edu
First you make a roux!
Technical Details
Message-ID: <1277@bingvaxu.cc.binghamton.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!uwvax!rutgers!sunybcs!bingvaxu!marge.math.binghamton.edu!sullivan
References: <898@acornrc.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!uwvax!rutgers!sunybcs!bingvaxu!marge.math.binghamton.edu!sullivan
From: sullivan@marge.math.binghamton.edu (fred sullivan)
Newsgroups: comp.lang.modula2
Subject: Re: Need filter to raise keywords to uppercase
Message-ID: <1277@bingvaxu.cc.binghamton.edu>
Date: 18 Jun 88 22:51:47 GMT
References: <898@acornrc.UUCP>
Sender: news@bingvaxu.cc.binghamton.edu
Reply-To: sullivan@marge.math.binghamton.edu.cc.binghamton.edu (fred sullivan)
Organization: SUNY Binghamton, NY
Lines: 132