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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1be1b347b5b5ad43 X-Google-Attributes: gid103376,public From: Ray Blaak Subject: Re: Ayacc/Aflex "entropy" (P2Ada) Date: 1999/10/25 Message-ID: #1/1 X-Deja-AN: 540236540 Sender: blaak@vault84.infomatch.bc.ca References: <3813716C.52655126@Maths.UniNe.CH> X-Trace: news.bctel.net 940838761 207.34.170.82 (Mon, 25 Oct 1999 01:06:01 PDT) NNTP-Posting-Date: Mon, 25 Oct 1999 01:06:01 PDT Newsgroups: comp.lang.ada X-Complaints-To: news@bctel.net Date: 1999-10-25T00:00:00+00:00 List-Id: Gautier writes: > I've observed the phenomenon that most enhancements brought to Pascal.Y in my > attempts to extend P2Ada for the Borland-ish Pascal language "nebula" > increases the "Reduce/Reduce conflicts" (what does it mean? nothing good > surely...) and can confuse the translator in unexpected way. > > - Is there a strategy to avoid it (I'm completely amateur in ayacc) ? I have worked on a Delphi reverse engineering tool* for Rational Rose, and have implemented a Delphi (Object Pascal) parser. Let's just say I feel your pain. Delphi has many strange quirks that cause ambiguities in a straight forward yacc-like grammar. Single token look ahead is very often not enough to decide how to resolve to a rule. The problems are related to the fact than many "keywords" are not in fact reserved. All of the procedure directives, for example, are not (e.g. the "virtual" in "procedure Method; virtual;". Semicolons are often optional, which really makes life difficult for a parser (e.g. "procedure Method virtual;" is also fine). The Delphi compiler tolerates a fair bit of divergence from its official description, which also makes life interesting. The ways to resolve this are as follows: - Use a better tool. Visual Parse, for example, supports n-token look ahead (at the cost of probable exponential explosion). This is not useful for a publicly available grammar file however (VP is a Windows proprietary parsing system). - Use a completely different tool. Recursive descent? I don't know what freely available tools are out there. - Bite the bullet and deal with each ambiguity explicitly by constructing precise descriptions of how things can be resolved. Avoid null rules at all costs. For example, a record type looks like: = "record" "end" = | | Note the empty choice that makes a record body optional. This kind of thing, however, tends to screw up parsers. Instead, make things explicit: = "record" "end" | "record" "end" = | For what its worth, ayacc is probably as good as any other yacc tool. The real work is to make the grammar rules unambiguous. * See http://www.ensemble-systems.com if you are interested. It is called the Rose Delphi Link -- Cheers, The Rhythm is around me, The Rhythm has control. Ray Blaak The Rhythm is inside me, blaak@infomatch.com The Rhythm has my soul.