Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!news-out.readnews.com!news-xxxfer.readnews.com!news.misty.com!news.iecc.com!nerds-end From: "Armel" Newsgroups: comp.compilers Subject: Re: coupling LALR with a scanner? Date: Mon, 19 Sep 2011 13:52:06 +0200 Organization: les newsgroups par Orange Lines: 30 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <11-09-021@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> NNTP-Posting-Host: news.iecc.com X-Trace: gal.iecc.com 1316460510 40723 64.57.183.58 (19 Sep 2011 19:28:30 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Mon, 19 Sep 2011 19:28:30 +0000 (UTC) Keywords: parse Posted-Date: 19 Sep 2011 15:28:30 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:271 >[This seems like an awfully complicated way to reinvent scanner start >states. -John] In Fact, This Is The Same. there is a big difference in usage with start states guided through Bison/Yacc explicit actions: the scanner knows by itself which start state to use AND can tell you up front that what you expect to do is impossible. when two mutually exclusive tokens happen in the same parser state e.g. A => expr "/" expr | expr REGEXPR expr // imagining its possible in your language B => expr "/" expr expr => number | REGEXPR REGEXPR = /[^/]*/ In case A the parser generator would issue by itself an error, in case B, it would set automatically the lexer start states appropriately. In both case it has a tremendous advantage: any developer can enter the grammar, compile and have something working (or know why it won't work), s/he does not need any more to be a scanner/parser guru. By the way, nothing prevents start states with exclusive tokens from being stuffed with all the other non-problematic tokens, so as to give meaningful messages when an unexpected token happens. Regards Armel