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=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!mx05.eternal-september.org!feeder.eternal-september.org!news.glorb.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: LALR parser question References: <85sj2aydwi.fsf@stephe-leake.org> Date: Fri, 03 May 2013 04:45:41 -0500 Message-ID: <85zjwc8khm.fsf@stephe-leake.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (windows-nt) Cancel-Lock: sha1:vPuu7UCOEULgYlIHEahM2AIAuts= MIME-Version: 1.0 Content-Type: text/plain X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: abac251838746c7c1c72706213 X-Received-Bytes: 3015 Xref: news.eternal-september.org comp.lang.ada:15316 Date: 2013-05-03T04:45:41-05:00 List-Id: "Randy Brukardt" writes: > "Stephen Leake" wrote in message > news:85sj2aydwi.fsf@stephe-leake.org... >> As part of Emacs Ada mode 5.0, I'm building a generalized LALR grammar >> for Ada (see >> http://stephe-leake.org/emacs/ada-mode/emacs-ada-mode.html#ada-mode-5.0 ) >> >> I'm having trouble with empty declarations. For example (using Bison >> syntax for the grammar), a simplified subset of the Ada package_body sytax >> is: >> >> package_body >> : IS declaration_list BEGIN SEMICOLON >> ; >> >> declaration_list >> : declaration >> | declaration_list declaration >> ; >> >> declaration >> : object_declaration >> | subprogram_declaration >> ;; ... >> ; >> >> 1) Add an empty declaration choice to declaration_list: >> >> declaration_list >> : ;; empty list >> | declaration_list declaration >> ; >> > > 2) Add an empty declaration choice to declaration: > > > > declaration > > : ;; empty declaration > > | object_declaration > > | subprogram_declaration > > ;; ... > > ; > Choice 1 here is the best way to do this for an LALR(1) grammar. The > equivalent part of the Janus/Ada grammer reads: > > package_body ::= package_head declarative_part block_option ## 8 > > declarative_part ::= dec_option ## 0 > dec_option ::= pragma_option > | dec_option declaration pragma_option > | dec_option body_dec pragma_option ## 0 > > pragma_option ::= pragma_option pragma_stmt > | ## 0 -- Empty production > > "declaration" and "body_dec" include the usual suspects, and no empty > parts. This actually the same as my choice 2; the empty production is not in the list rule (dec_option), it's in one of the options of that rule (pragma_option). > This generates a grammar with no conflicts. I get a conflict with choice 2, but I now believe that's a bug; I think there's something wrong with the lookahead propagation step. >> Any other ways to handle this problem? > > Get a better parser generator?? I'm fixing OpenToken; I'm asking if the OpenToken behavior for choice 1 is a bug. You have not directly addressed that, but thanks for letting me know someone is using LALR in a commercial product! -- -- Stephe