Version 1.1 of acs/ac-00202.txt

Unformatted version of acs/ac-00202.txt version 1.1
Other versions for file acs/ac-00202.txt

!standard 12.3(5)          10-10-21 AC95-00202/01
!class confirmation 10-10-21
!status received no action 10-10-21
!status received 10-05-06
!subject Ambiguities in the BNF grammar
!summary
!appendix

!topic Ada 2005 RM ambiguities in the BNF grammar for generics
!reference Ada 2005 RMRM95-12.3
!from Bruno Le Hyaric 10-05-06
!keywords bnf grammar ambiguities generics
!discussion



Hi,

I am working on implementing the grammar for Ada 2005 based on your document.

I have quite finished, but I found what seems to be ambiguities
regarding generics.

In 12.3:
explicit_generic_actual_parameter ::= expression | variable_name
| subprogram_name | entry_name | subtype_mark
| package_instance_name

*) Why do you use variable_name, subprogram_name, entry_name and
package_instance_name? The BNF grammar should declare syntactic rules,
not semantic rules.
In my implementation, all this non-terminals become 'name'. Is that
right? (the semantic verification should arrive after the parsing...).

In 12.4:
formal_object_declaration ::=
defining_identifier_list : mode [null_exclusion] subtype_mark [:=
default_expression];
defining_identifier_list : mode access_definition [:= default_expression];

*) I think a ellipsis '|' is missing between the two alternatives.
This rule should be like this I guess :

defining_identifier_list : mode [null_exclusion] subtype_mark [:=
default_expression];
| defining_identifier_list : mode access_definition [:= default_expression];

*) I use TXL as a base for static analysis of Ada 2005. So I am
rewriting the entire grammar (in a BNF-style grammar). I planned to
deliver it in the opensource world, and I would appreciate to have
someone to use, check and comment my work after that... Did you have
any contact, who could be interested for this?

***************************************************************

From: Randy Brukardt
Sent: Thursday, May 6, 2010  5:56 PM

> In 12.3:
> explicit_generic_actual_parameter ::= expression | variable_name
> | subprogram_name | entry_name | subtype_mark package_instance_name
>
> *) Why do you use variable_name, subprogram_name, entry_name and
> package_instance_name? The BNF grammar should declare syntactic rules,
> not semantic rules.

I don't have any idea why this particular grammar production was written this
way: this production was written this way in Ada 83 and has been unchanged
since. I was a graduate student when it was written...

In any case, you seem to have a misinterpretation about the way the Ada grammar
is defined and used. First of all, it is ambiguous in many places. Why the
original authors of Ada thought this was a good idea remains a mystery to me,
but it is not something that we are going to change (as it would certainly cause
the introduction of new errors, and would have no effect on users or
implementations). Secondly, the grammar does carry some semantic information for
readability. I believe that most of that information is also backed up by
specific English legality rules -- but it is a long-standing Ada tradition
(going back to the original 1980 version of the language) and I think there is
absolutely no interest in changing it.

Finally, the grammar is not complete, either, as there are English-language syntax rules in various places in the Standard. (The rules for the use of "others" clauses is one example.) We're even adding more in Ada 2012: the description of the syntax for pa
rentheses when used around conditional expressions is much better described in one paragraph of English than more than a page of syntax changes (we worked out both).

There are a number of sources for unambiguous Ada grammars around, but the
Standard is not one of them.

> In my implementation, all this non-terminals become 'name'.
> Is that right? (the semantic verification should arrive after the
> parsing...).

The idea is that the italic portions are dropped when doing purely syntactic
processing. This is explained in 1.1.4(14). You should reread clause 1.1.4 as it
ought to make it clear what the meaning of the grammar in the Standard is.

> In 12.4:
> formal_object_declaration ::=
> defining_identifier_list : mode [null_exclusion] subtype_mark [:=
> default_expression]; defining_identifier_list : mode access_definition
> [:= default_expression];
>
> *) I think a ellipsis '|' is missing between the two alternatives.

Yes, this was noticed long ago and fixed in the next version. Note that this is
simply an editing error in the unofficial consolidated standard: the actual
language Standard (which is in three parts) has this correct.

...
> *) I use TXL as a base for static analysis of Ada 2005. So I am
> rewriting the entire grammar (in a BNF-style grammar). I planned to
> deliver it in the opensource world, and I would appreciate to have
> someone to use, check and comment my work after that... Did you have
> any contact, who could be interested for this?

Perhaps someone else here will know an answer.

***************************************************************

From: Bruno Le Hyaric
Sent: Monday, May 17, 2010  5:15 PM

Hi every body,

I've recently made up a new grammar for Ada based on the great language
manipulation tool : TXL (http://www.txl.ca).

http://github.com/bu2/ada-2005-txl-grammar

The grammar is currently at an early stage. It permits to parse full Ada 2005
following LRM standard but still only provide parsing trees.

AST coming soon and even more...


Comments are welcome!

***************************************************************

Questions? Ask the ACAA Technical Agent