Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!news.iecc.com!nerds-end From: "BartC" Newsgroups: comp.compilers Subject: Re: Ignore break line sometimes Date: Tue, 14 Feb 2012 00:25:04 -0000 Organization: A noiseless patient Spider Lines: 31 Sender: johnl@iecc.com Approved: comp.compilers@iecc.com Message-ID: <12-02-020@comp.compilers> References: <12-02-010@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: leila.iecc.com 1329180135 6743 64.57.183.58 (14 Feb 2012 00:42:15 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Tue, 14 Feb 2012 00:42:15 +0000 (UTC) Keywords: parse Posted-Date: 13 Feb 2012 19:42:15 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: x330-a1.tempe.blueboxinc.net comp.compilers:460 "Geovani de Souza" wrote > I'm trying write an parser to my compiler, and I'm interessed to ignore > the break line (\n) sometimes. E.g: > > if true then [\n] > foo(); [\n] > end; [\n] > > So, in the first line, the '\n' after 'then' isn't important, but in the > second "foo();" could replace the need of the semicolon to conclude the > statement, or still, in the 'end'. > > To ignore '\n' in the white lines. I've tried a few schemes. One just converts a newline to a semicolon, *unless* the last symbol was (for example) a comma. This requires some sort of continuation symbol for when a semicolon would be inappropriate. And it helps if the grammar is tolerant of extra semicolons, otherwise the source code could be full of continuation symbols! (After 'then' for example.) Whatever scheme you choose, you'll know it works well when you have thousands of lines of code without a single semicolon, and hardly any continuations. And that is perfectly clear to read. -- Bartc