Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!olivea!mintaka!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: a style question Message-ID: <18393@haddock.ima.isc.com> Date: 3 Oct 90 04:44:29 GMT References: <7341@darkstar.ucsc.edu> <8660@ncar.ucar.edu> <1990Sep30.220839.20183@nntp-server.caltech.edu> <1990Oct1.174625.22061@zoo.toronto.edu> <1990Oct2.163853.17004@nntp-server.caltech.edu> Reply-To: karl@kelp.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 34 In article <1990Oct2.163853.17004@nntp-server.caltech.edu> manning@nntp-server.caltech.edu (Evan Marshall Manning) writes: >henry@zoo.toronto.edu (Henry Spencer) writes: >>In what way is "ix" superior to "i"? Both are meaningless names ... > >If Henry asks it must not be as self evident as I thought. Hasn't this >ever happened to you: [You want to search for the variable "i" to see where >it's being used.] You find that a lower case 'i' appears an average of about >four times per comment line. Ah yes, that's a different problem. I solved it by improving my toolbox. >'ix' appears in the comments only when the comments are about variable 'ix'. Or when it mentions "Unix". Solution: Use searching tools that know about word boundaries. Both vi and emacs have such support. Some versions of grep can do it too. If yours doesn't, then write a filter that flags the beginning and end of each word with a special string, and use "wordflag | grep | wordunflag". (The last one can be a one-line sed script.) The next annoying problem is when you want to find the variable "n" or "s", and even in word-search mode you get false hits on strings like "%s\n". Write another tool that filters a C source and keeps track of the lexical state at all times. Mine distinguishes 8 states: {program text, character literal, string literal, comment} x {preprocessor line, real line}; the user selects which states are of interest. Exercise: By writing a word-flagging tool that can be used in a pipeline, rather than adding word-boundary recognition to grep, we have a more general tool that may have other applications. In keeping with this spirit, what should be the semantics of the C-lexing tool? Karl W. Z. Heuer (karl@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint