From: Ray Blaak <blaak@infomatch.com>
Subject: Re: Ayacc/Aflex "entropy" (P2Ada)
Date: 1999/10/25
Date: 1999-10-25T00:00:00+00:00 [thread overview]
Message-ID: <m31zajdfv9.fsf@vault84.infomatch.bc.ca> (raw)
In-Reply-To: 3813716C.52655126@Maths.UniNe.CH
Gautier <Gautier.deMontmollin@Maths.UniNe.CH> 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> = "record" <record_body> "end"
<record_body> = | <field> | <record_body> <field>
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> = "record" "end" | "record" <record_body> "end"
<record_body> = <field> | <record_body> <field>
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.
next prev parent reply other threads:[~1999-10-25 0:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-10-24 0:00 Ayacc/Aflex "entropy" (P2Ada) Gautier
1999-10-25 0:00 ` Ted Dennison
1999-10-26 0:00 ` Robert Dewar
1999-10-26 0:00 ` Gautier
1999-10-27 0:00 ` Tarjei Jensen
1999-10-27 0:00 ` David Botton
1999-10-26 0:00 ` bourguet
1999-10-26 0:00 ` Robert I. Eachus
1999-10-27 0:00 ` Robert Dewar
1999-10-27 0:00 ` Ted Dennison
1999-10-27 0:00 ` bourguet
1999-10-29 0:00 ` Robert I. Eachus
1999-10-31 0:00 ` Robert Dewar
1999-11-01 0:00 ` Robert I. Eachus
1999-10-26 0:00 ` Ted Dennison
1999-10-26 0:00 ` William B. Clodius
1999-10-26 0:00 ` David Starner
1999-10-26 0:00 ` Robert Dewar
1999-10-30 0:00 ` Brian Rogoff
1999-10-31 0:00 ` Robert Dewar
1999-10-25 0:00 ` Ted Dennison
1999-10-25 0:00 ` Ray Blaak [this message]
1999-10-25 0:00 ` Gautier
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox