From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,13b4e394fcd91d4 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.238.198 with SMTP id vm6mr4370423pbc.3.1327682937265; Fri, 27 Jan 2012 08:48:57 -0800 (PST) Path: lh20ni230462pbb.0!nntp.google.com!news2.google.com!eweka.nl!feeder.eweka.nl!62.179.104.142.MISMATCH!amsnews11.chello.com!txtfeed2.tudelft.nl!tudelft.nl!txtfeed1.tudelft.nl!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!gegeweb.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: OpenToken: Handling the empty word token Date: Fri, 27 Jan 2012 17:48:45 +0100 Organization: cbb software GmbH Message-ID: <1jvlv7i0tn14u.b5d2cwsqhl2h$.dlg@40tude.net> References: <62121d9d-f208-4e78-a109-749742da14a6@h12g2000yqg.googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: CNp+VBSYV+ysZXOiVRxJxw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2012-01-27T17:48:45+01:00 List-Id: On Fri, 27 Jan 2012 08:22:12 -0800 (PST), mtrenkmann wrote: > Is there a way to instrument the parser to silently accept the epsilon > token whenever it expects it without consuming a token from the lexer, > or is it a common convention to translate each grammar into a epsilon- > free representation? I use neither explicit grammars nor OpenToken, so it is possible that I didn't really understand the problem you have. For a table-driven parser, which I am using, there are two ways to handle implied tokens, which, I suppose, is what you wanted: 1. You could put an empty string into the table and let that be recognized. It is a straightforward approach which has the disadvantage that empty string is always matched, so when you have a recursive grammar you might run into an endless loop of matching the empty string over and over again if the parser's state is not really changed. 2. A better way is to connect to the semantic callback on "something expected." For example, to handle for example assumed multiplication in infix expressions, e.g. A B + C => A*B + C, I connect to "on missing operation" and push the multiplication onto the operation stack. That is. This is not really different from how you would handle a missing right bracket. Once the parser detected that, you would push the bracket onto the stack and continue (if you allow recovery on such errors). -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de