Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.lightlink.com!news.iecc.com!lnews.iecc.com!nerds-end From: Chris Dodd Newsgroups: comp.compilers Subject: Re: coupling LALR with a scanner? Date: 23 Sep 2011 23:59:35 +0100 Organization: X-Privat.Org NNTP Server - http://www.x-privat.org Lines: 23 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <11-09-029@comp.compilers> References: <11-07-013@comp.compilers> <11-07-015@comp.compilers> <11-07-018@comp.compilers> <11-08-004@comp.compilers> <11-09-016@comp.compilers> <11-09-017@comp.compilers> <11-09-022@comp.compilers> <11-09-023@comp.compilers> NNTP-Posting-Host: lnews.iecc.com X-Trace: gal.iecc.com 1316982586 8817 64.57.183.34 (25 Sep 2011 20:29:46 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sun, 25 Sep 2011 20:29:46 +0000 (UTC) Keywords: parse, yacc Posted-Date: 25 Sep 2011 16:29:46 EDT 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:279 "Armel" wrote in news:11-09-023@comp.compilers: > Of course in the presence of something like expr / expr the parser knows > the / is for a division, and if the / is found where expr is expected it > knows there is a regular expression coming. > I don't see how I could hack this into a scanner only. maybe some > specific preceding tokens. I have pass again some time on that question. The usual way to do this in a flex+bison parser is with a production like: expr: { beginREGEXP(); } '/' regexp { endREGEXP(); } '/' where beginREGEXP and endREGEXP are functions in the flex file that set the start-state into and out of regexp mode. Note that the actions need to be BEFORE the parser shifts the '/' token, as an LALR(1) parser may look ahead one token. Which means that a '/' must be a '/' regardless of the scanner state. Note that if you allow additional lookahead in the parser (LR(k) or LR(*) or any kind of backtracking) this will break badly. Chris Dodd cdodd@acm.org