Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.misty.com!news.iecc.com!.POSTED!nerds-end From: glen herrmannsfeldt Newsgroups: comp.compilers Subject: Re: Parsing Fortran, was specifying semantics Date: Fri, 4 Jul 2014 17:53:31 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 44 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <14-07-013@comp.compilers> References: <14-06-010@comp.compilers> <14-06-023@comp.compilers> <14-06-025@comp.compilers> <14-06-027@comp.compilers> <14-06-030@comp.compilers> <14-06-031@comp.compilers> <14-07-003@comp.compilers> <14-07-006@comp.compilers> <14-07-011@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: miucha.iecc.com 1404497151 6612 2001:470:1f07:1126:0:676f:7373:6970 (4 Jul 2014 18:05:51 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Fri, 4 Jul 2014 18:05:51 +0000 (UTC) Keywords: Fortran, comment Posted-Date: 04 Jul 2014 14:05:51 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.compilers:1303 Hans-Peter Diettrich wrote: (snip) > whitespace popped up, where whitespace sometimes is required to separate > keywords from identifiers, sometimes is optional: > Fortran: D O I = ... > Pascal: if x ... > C: int i ... (snip) > [You can scan Fortran with longest match, but the things you're > matching for are very context dependent. I've done it. I agree that > it's unlikely we'll find a general model for different languages. -John] The two favorite ones that I always remember for Fortran are: DO1I=1,2 and DO 1 I=1.2 (and with no IMPLICIT NONE in effect, or with DO1I already declared). To avoid these kinds of problems, WATFIV disallows "FORMAT(" as the first seven characters of a statement that isn't a FORMAT statement. Doesn't seem like it is overly restrictive, but when using variable format, I always called my array (it had to be an array back then) FORMAT. -- glen [To parse a Fortran statement you first have to decide whether it's an assignment or something else, after which you can use a simple contnext sensitive longest match to find the tokens. To see if it's an assignment, you look for an = sign that is not followed by a comma that is not inside parens, being sure to skip over 'literal' and 9hHollerith strings and noting that in typical dialects the statement REAL*4HFOO does not contain a Hollerith string.. It wasn't as hard as it sounds. -John]