Path: csiph.com!feeder.erje.net!2.us.feeder.erje.net!news.glorb.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: George Neuner Newsgroups: comp.compilers Subject: Re: antlr Date: Wed, 23 Mar 2016 02:56:00 -0400 Organization: A noiseless patient Spider Lines: 47 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <16-03-006@comp.compilers> References: <16-03-001@comp.compilers> <16-03-004@comp.compilers> <16-03-005@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit Injection-Info: miucha.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="30794"; mail-complaints-to="abuse@iecc.com" Keywords: PCCTS, tools Posted-Date: 25 Mar 2016 14:10:36 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1678 On Tue, 22 Mar 2016 23:54:19 -0400, ruben safir wrote: >On Tue, 15 Mar 2016 10:53:25 -0400, George Neuner wrote: > >> Antlr now is supported mainly on Stackoverflow.com and via a Google >> group. see http://www.antlr.org/support.html > >Lets try usenet > >I have two grammars, one with white space > >WS : [ \n\t\r]+ ->skip; > > >and one, or two actually, for comments >COMMENT: '#' .*? '\n' -> channel(HIDDEN); >COMMENT2: '/*' .*? '*/' -> channel(HIDDEN); //This pulls through > //linefeeds? > >What is the practical difference between the channel(HIDDEN) and the skip "skip" just throws away the match. There is no token produced for anything that is skipped. "channel" is a bit more complicated. Antlr uses named streams - "channels" - to communicate between the lexer and parser. The parser only draws tokens from one stream at a time (but you can change which stream it follows). There are two built in channels: DEFAULT and HIDDEN. The parser (unless told otherwise) listens to DEFAULT. Tokens sent to HIDDEN are not parsed, but are still available to be inserted back into output later. This is useful for, e.g., source->source transformations preserving comments. You can define other channels for different purposes, e.g., an embedded DSL could be handled by a separate parser. Unfortunately a useful example would be complicated. The online documentation tracks the state of the latest version, but the best source for insight into how Antlr works is Terence's book. George