Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!hao!bill From: bill@hao.UUCP (Bill Roberts) Newsgroups: net.unix Subject: Re: Regular Expressions in Lex (Lexing Fortran) Message-ID: <165@hao.UUCP> Date: Fri, 25-Jul-86 11:34:38 EDT Article-I.D.: hao.165 Posted: Fri Jul 25 11:34:38 1986 Date-Received: Fri, 25-Jul-86 21:35:15 EDT Organization: High Altitude Obs./NCAR Boulder, CO Lines: 50 Keywords: arg!, ackpht Thanks to all who responded to my earlier query (msgs # 9080). I finally got it figured out the other day and thought some people might be interested in the solution. To restate the problem: I needed a regular expression to use as part of a lex input file to dig out all syntactically valid instances of f77 open statements, in their various guises. That is, I want to find things like if (fred .eq. betty) 1 open(unit=1, file=fred, .... ) and open(unit=1, ...., # more.............., @ xya, abc, and more, . . . n and finally this) as well as regular things like open (fred the open statement) In addition, I wanted to ignore any commented open statements. One solution is this: (note that this is a Lex input file) C \n" ". A [ \t{C}]* B [ \t] D [^=\n] %% ^{B}+{D}*o{A}p{A}e{A}n{A}\(.*({C}.*)*\)[ ]*\n { return(OPENR); } . ; \n ; This seems to work on all of the cases I've stated above (are there others?). It even handles the cases where the 'open' word is separated by spaces, tabs, or newlines (as is allowed in fortran, arg!). I hope this might be of interest or help to someone out there. It was quite enlightening (and frustrating) to me. I only had to read the Lex paper ("Lex - A Lexical Analyzer Generator", M.E. Lesk and E. Schmidt) n times! Bill Roberts NCAR/HAO Boulder, CO !hao!bill