Path: 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 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 %% {a}{b}{s} printf("ABS"); {a}{n}{d} printf("AND"); {a}{r}{r}{a}{y} printf("ARRAY"); {b}{e}{g}{i}{n} printf("BEGIN"); {b}{i}{t}{s}{e}{t} printf("BITSET"); {b}{o}{o}{l}{e}{a}{n} printf("BOOLEAN"); {b}{y} printf("BY"); {c}{a}{p} printf("CAP"); {c}{a}{r}{d}{i}{n}{a}{l} printf("CARDINAL"); {c}{a}{s}{e} printf("CASE"); {c}{h}{a}{r} printf("CHAR"); {c}{h}{r} printf("CHR"); {c}{o}{n}{s}{t} printf("CONST"); {d}{e}{c} printf("DEC"); {d}{e}{f}{i}{n}{i}{t}{i}{o}{n} printf("DEFINITION"); {d}{i}{s}{p}{o}{s}{e} printf("DISPOSE"); {d}{i}{v} printf("DIV"); {d}{o} printf("DO"); {e}{l}{s}{e} printf("ELSE"); {e}{l}{s}{i}{f} printf("ELSIF"); {e}{n}{d} printf("END"); {e}{x}{c}{l} printf("EXCL"); {e}{x}{i}{t} printf("EXIT"); {e}{x}{p}{o}{r}{t} printf("EXPORT"); {f}{a}{l}{s}{e} printf("FALSE"); {f}{l}{o}{a}{t} printf("FLOAT"); {f}{o}{r} printf("FOR"); {f}{r}{o}{m} printf("FROM"); {h}{a}{l}{t} printf("HALT"); {h}{i}{g}{h} printf("HIGH"); {i}{f} printf("IF"); {i}{m}{p}{l}{e}{m}{e}{n}{t}{a}{t}{i}{o}{n} printf("IMPLEMENTATION"); {i}{m}{p}{o}{r}{t} printf("IMPORT"); {i}{n} printf("IN"); {i}{n}{c} printf("INC"); {i}{n}{c}{l} printf("INCL"); {i}{n}{t}{e}{g}{e}{r} printf("INTEGER"); {l}{o}{o}{p} printf("LOOP"); {m}{o}{d} printf("MOD"); {m}{o}{d}{u}{l}{e} printf("MODULE"); {n}{e}{w} printf("NEW"); {n}{i}{l} printf("NIL"); {n}{o}{t} printf("NOT"); {o}{d}{d} printf("ODD"); {o}{f} printf("OF"); {o}{r} printf("OR"); {o}{r}{d} printf("ORD"); {p}{o}{i}{n}{t}{e}{r} printf("POINTER"); {p}{r}{o}{c} printf("PROC"); {p}{r}{o}{c}{e}{d}{u}{r}{e} printf("PROCEDURE"); {q}{u}{a}{l}{i}{f}{i}{e}{d} printf("QUALIFIED"); {r}{e}{a}{l} printf("REAL"); {r}{e}{c}{o}{r}{d} printf("RECORD"); {r}{e}{p}{e}{a}{t} printf("REPEAT"); {r}{e}{t}{u}{r}{n} printf("RETURN"); {s}{e}{t} printf("SET"); {t}{h}{e}{n} printf("THEN"); {t}{o} printf("TO"); {t}{r}{u}{e} printf("TRUE"); {t}{r}{u}{n}{c} printf("TRUNC"); {t}{y}{p}{e} printf("TYPE"); {u}{n}{t}{i}{l} printf("UNTIL"); {v}{a}{l} printf("VAL"); {v}{a}{r} printf("VAR"); {w}{h}{i}{l}{e} printf("WHILE"); {w}{i}{t}{h} printf("WITH"); [a-zA-Z][a-zA-Z0-9]* ECHO; \(\* { ECHO; commentlevel = 1; BEGIN COMMENT; } \*\) { ECHO; if (--commentlevel == 0) BEGIN OTHER; } \(\* { ECHO; ++commentlevel; } \" { ECHO; BEGIN DSTRING; } \" { ECHO; BEGIN OTHER; } \' { ECHO; BEGIN 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!