comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Ada grammar rules for names too permissive?
Date: Mon, 31 Dec 2018 15:45:44 -0600
Date: 2018-12-31T15:45:44-06:00	[thread overview]
Message-ID: <q0e2m8$t6b$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 30ba8954-a19e-4c95-b350-798b0276db41@googlegroups.com

Ada semantic rules use the syntax rules and vice versa. In this case, one 
does not want to repeat the various rules for interpreting an expanded name 
(which are part of selected_component).

In this particular case, the resolution rule for subtype_mark eliminates any 
nonsense cases.

There's also two practical considerations: one is that with typical grammar 
generators, you usually have to allow more syntax than you want, as 
differentiating between options requires essentially unlimited lookahead. 
(Most grammar generators use a single token lookahead.) In this case, you 
would have a lot of trouble telling between a type conversion and an indexed 
component, if the prefix syntax was different for each.

Secondly, error detection for generated grammars tends to be less 
understandable than hand written error handling. (My understanding is that 
this is a major reason why GNAT uses a hand-written parser.) So allowing too 
much syntactically allows providing better error messages.

For instance, one could easily require "others" to stand alone with your 
grammar. However, if you do that, the error message ends up being something 
like "unexpected |", which is not very helpful.

                              Randy.

<olivermkellogg@gmail.com> wrote in message 
news:30ba8954-a19e-4c95-b350-798b0276db41@googlegroups.com...
> Hi,
>
> RM section 3.2.2 defines
>
>  subtype_mark ::= (subtype_)name
>
> where (subtype_) is subtype_ rendered in italics, i.e. essentially
>
>  subtype_mark ::= name
>
> This looks overly permissive to me, considering 4.1
>
>  name ::=
>     direct_name | explicit_dereference
>   | indexed_component | slice
>   | selected_component | attribute_reference
>   | type_conversion | function_call
>   | character_literal | qualified_expression
>   | generalized_reference | generalized_indexing
>   | target_name
>
> The AARM elaborates in paragraph 4a:
>
> *Ramification*: Note that name includes attribute_reference; thus, S'Base 
> can be used as a subtype_mark.
>
> My question is, why is subtype_mark not defined as follows:
>
>  compound_name ::= identifier { . identifier }
>
>  subtype_mark ::= compound_name [ ' Base ]
>
>
> Similarly, RM section 10.1.1 defines
>
>  parent_unit_name ::= name
>
> Here my question also applies, why not
>
>  parent_unit_name ::= compound_name
>
>
> - Oliver
> (currently fighting ambiguities in the ANTLR grammar caused by laxity of 
> rules) 


  reply	other threads:[~2018-12-31 21:45 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-29 18:20 Ada grammar rules for names too permissive? olivermkellogg
2018-12-31 21:45 ` Randy Brukardt [this message]
2019-01-01  8:44   ` Dmitry A. Kazakov
2019-01-01 19:49     ` Stephen Leake
2019-01-01 20:42       ` Dmitry A. Kazakov
2019-01-02 19:21         ` Stephen Leake
2019-01-02 20:47           ` Dmitry A. Kazakov
2019-01-03 21:45             ` Stephen Leake
2019-01-03 22:34               ` Jere
2019-01-05 18:46                 ` Stephen Leake
2019-01-07 11:11                   ` J-P. Rosen
2019-01-08 18:58                     ` Stephen Leake
2019-01-04  8:53               ` Dmitry A. Kazakov
2019-01-03 22:39     ` olivermkellogg
2019-01-04  8:58       ` Dmitry A. Kazakov
2019-01-05  8:45         ` Randy Brukardt
2019-01-05 18:50       ` Stephen Leake
2019-01-01 19:46   ` olivermkellogg
2019-01-03 22:36     ` Randy Brukardt
2019-01-01 19:46 ` Stephen Leake
2019-01-01 21:03   ` olivermkellogg
2019-01-02 19:42     ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox