Re: BNF notation for Delphi Grammar

George Neuner <gneuner2@comcast.net>
8 Jun 2005 22:36:15 -0400

          From comp.compilers

Related articles
BNF notation for Delphi Grammar gustgr@gmail.com (2005-05-31)
Re: BNF notation for Delphi Grammar haberg@math.su.se (2005-06-02)
Re: BNF notation for Delphi Grammar gneuner2@comcast.net (George Neuner) (2005-06-06)
Re: BNF notation for Delphi Grammar DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2005-06-08)
Re: BNF notation for Delphi Grammar franck.pissotte@alussinan.org (Franck Pissotte) (2005-06-08)
Re: BNF notation for Delphi Grammar gneuner2@comcast.net (George Neuner) (2005-06-08)
Re: BNF notation for Delphi Grammar frank@g-n-u.de (2005-06-12)
| List of all articles for this month |
From: George Neuner <gneuner2@comcast.net>
Newsgroups: comp.compilers
Date: 8 Jun 2005 22:36:15 -0400
Organization: Compilers Central
References: 05-05-230 05-06-037 05-06-042
Keywords: Pascal, parse
Posted-Date: 08 Jun 2005 22:36:15 EDT

On 8 Jun 2005 15:59:36 -0400, Hans-Peter Diettrich
<DrDiettrich@compuserve.de> wrote:


>Some people have tried to construct EBNF grammars for various Delphi
>versions in the past, but the results are questionable, for several
>reasons:
>
>- "directives" are reserved words in specific context.
>- the semantics are too far away from the syntax, in detail
>- semicolons can have unexpected (context sensitive) effects.
>
>My favorite example:
>
>case i of
>0: if a then b
>; //<----- illegal, optional or required?
>else c
>end;
>
>Normally a semicolon is illegal in this place, because it's intended to
>only separate multiple case-labels. In this special case the marked
>semicolon is not optional, in fact it indicates whether the following
>dangling "else" is part of the "if" or of the "case" statement.


I just looked in the manual for TP5 and I agree the your example is
ambiguous wrt the syntax diagrams ... I guess I never noticed it
before.


I don't know Delphi, but assuming that it follows Pascal rules I would
say that in your example the semicolon is required to guarantee
separation of the cases's else clause from the if statement.


When I learned Pascal I somehow got into the habit of always using a
begin-end block within a case clause ... I guess this situation never
bit me because of that.


George


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.