comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Is it really Ok to assert that the Ada syntax is a context-free grammar ?
Date: Wed, 20 Feb 2008 17:19:25 +0200
Date: 2008-02-20T17:19:25+02:00	[thread overview]
Message-ID: <47bc40e7$0$21890$4f793bc4@news.tdc.fi> (raw)
In-Reply-To: <9012d70c-8d61-4e2e-9eda-c12d48f1d9e1@s19g2000prg.googlegroups.com>

Hibou57 wrote:

> But I'm still not sure about the assertion that it is context free
> (while, Ok, the AEM does not tell it is LR(1))
> 
> If it need name resolution to figure out what means the construct,
> this is not a context-free grammar.

The *grammar* in the ARM is surely context-free. In each 
production, there is only one non-terminal symbol on the left-hand 
side, for example 6.4(3):

    function_call ::= prefix actual_parameter_part

In a context-dependent grammar, there would be several symbols on 
the left-hand side, before the "::=" sign.

The *Ada language* is not context-free, in the sense that the set 
of legal Ada programs cannot be defined by a context-free grammar. 
The same is true for all practical programming languages that allow 
user-defined identifiers with different properties, for example 
type identifiers and procedure identifiers, and that allow only 
some kinds of identifiers in some constructs. For example, you 
cannot "call" a type, but you can "call" a procedure.

The grammar in the ARM generates or accepts many strings that are 
not legal Ada programs. The "context-dependent narrative rules" are 
there to say which of these strings are legal Ada programs. This 
same definition method is used for most programming languages.

> Is this construct the only one of the grammar which is not context-
> free, or is there some others ?

Your are using the term "context-free" in some peculiar way, not in 
its usual meaning, I think.

It seems to me that you are really asking this question: given a 
*fragment* of an Ada program, for example "X(Y)", can this fragment 
be produced from more than one non-terminal grammar symbol?

I don't think that this has much to do with the context-freeness of 
the grammar, and I don't understand why you feel so strongly that 
there should be only one grammar symbol for each fragment.

For another example, consider the fragment

    delay 0.3

The way the grammar is now written, this fragment can (I think) be 
produced only from the non-terminal symbol delay_statement, by the 
rule in ARM 9.6(4). Does that make you happy? But look, the 
*meaning* of this fragment depends strongly on the context of this 
delay_statement: is it used as a

       simple_statement     (5.1(4))
or a  delay_alternative    (9.7.1(6))
or a  triggering_statement (9.7.4(4)) ?

These grammar rules could also be written without using the 
non-terminal symbol delay_statement, replacing it by the sequence 
consisting of the terminal symbol "delay" and the non-terminal 
symbol "expression". Then the fragment "delay 0.3" could be 
produced directly by any one of the three different non-terminal 
symbols (simple_statement, delay_alternative, 
triggering_statement). I don't think that change in the grammar 
would make any significant difference to the readability or 
parsability of Ada, so I don't see what your problem is.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



  reply	other threads:[~2008-02-20 15:19 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-20  0:47 Is it really Ok to assert that the Ada syntax is a context-free grammar ? Hibou57
2008-02-20  2:06 ` Jeffrey R. Carter
2008-02-20 10:05   ` Martin Krischik
2008-02-20 10:34     ` Ludovic Brenta
2008-02-20 11:13       ` Dmitry A. Kazakov
2008-02-22  8:57         ` Stephen Leake
2008-02-22 10:44           ` Dmitry A. Kazakov
2008-02-20 14:22       ` Hibou57
2008-02-20 15:19         ` Niklas Holsti [this message]
2008-02-20 18:34           ` Hibou57 (Yannick Duchêne)
2008-02-20 19:10             ` Hibou57 (Yannick Duchêne)
2008-02-21  0:39               ` Randy Brukardt
2008-02-21  0:56                 ` Hibou57 (Yannick Duchêne)
2008-02-21 22:19                   ` Randy Brukardt
2008-02-21 22:19                   ` Randy Brukardt
2008-02-21 23:54                     ` Hibou57 (Yannick Duchêne)
2008-02-22 19:51                       ` Randy Brukardt
2008-02-23 18:13                         ` Hibou57 (Yannick Duchêne)
2008-02-20 20:22             ` Niklas Holsti
2008-02-20 21:38             ` Manuel Collado
2008-02-21  0:30               ` Hibou57 (Yannick Duchêne)
2008-02-20 20:51         ` Robert A Duff
2008-02-21 19:24       ` Martin Krischik
2008-02-22 20:17         ` Simon Wright
2008-02-25 21:47           ` Samuel Tardieu
2008-02-23 19:02         ` Maciej Sobczak
2008-02-20 18:27     ` Jeffrey R. Carter
2008-02-21 19:20       ` Martin Krischik
2008-02-21 21:31         ` Jeffrey R. Carter
2008-02-20  5:53 ` Niklas Holsti
2008-02-20 16:43 ` Adam Beneschan
replies disabled

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