A
aegis
let's say we have the following declaration:
volatile int (*func)(int a);
We start with a declaration (A.2.2)
that expands to declaration-specifiers?
We find the right form:
type-qualifier declaration-specifiers opt?
after volatile is expanded, we look for
type specifier:
type-specifier declaration-specifiers opt
So after that is expanded we have:
(*func)(int a);
this counts as a init-declarator?
If so, then we expand it as a declarator
since it is not being initialized?
Then that brings us to the rule:
pointer opt direct-declarator
for (*func)(int a);
No pointer encountered yet, so we continue
expanding:
direct-declarator:
identifier
( declarator )
direct-declarator [ type-qualifier-list opt assignment-expression opt ]
direct-declarator [ static type-qualifier-list opt
assignment-expression ]
direct-declarator [ type-qualifier-list static assignment-expression ]
direct-declarator [ type-qualifier-list opt *]
direct-declarator ( parameter-type-list )
direct-declarator ( identifier-list opt )
We encounter ( declarator )
and reapply this rule?
If so, then the rule pointer opt direct-declarator
for declarator works here and we expand
the declarator part which qualifies as an
identifier. But that leaves us with:
(int a);
Which I wonder, where is the rule that should
be applied here that follows from our expansion?
Somewhere in the rules of direct declarator
we should branch to a rule that solves a parameter
list. But because our construction was (*func),
we should ignore the identifier in parens after
resolving that it was an identifier from
the direct declarator rule, right?
This is where I don't see how we branch to
a rule that resolves the parameter list.
I don't think it would be the following
rule:
direct-declarator ( parameter-type-list )
unless we consider the expanded identifier
as a direct declarator?
Also, chris torek, if you are reading this,
what data structure would you recommend for
representing this? I read an older
article by you that describes this process
as being in factored form. How do you recommend
to factor it all programmatically?
volatile int (*func)(int a);
We start with a declaration (A.2.2)
that expands to declaration-specifiers?
We find the right form:
type-qualifier declaration-specifiers opt?
after volatile is expanded, we look for
type specifier:
type-specifier declaration-specifiers opt
So after that is expanded we have:
(*func)(int a);
this counts as a init-declarator?
If so, then we expand it as a declarator
since it is not being initialized?
Then that brings us to the rule:
pointer opt direct-declarator
for (*func)(int a);
No pointer encountered yet, so we continue
expanding:
direct-declarator:
identifier
( declarator )
direct-declarator [ type-qualifier-list opt assignment-expression opt ]
direct-declarator [ static type-qualifier-list opt
assignment-expression ]
direct-declarator [ type-qualifier-list static assignment-expression ]
direct-declarator [ type-qualifier-list opt *]
direct-declarator ( parameter-type-list )
direct-declarator ( identifier-list opt )
We encounter ( declarator )
and reapply this rule?
If so, then the rule pointer opt direct-declarator
for declarator works here and we expand
the declarator part which qualifies as an
identifier. But that leaves us with:
(int a);
Which I wonder, where is the rule that should
be applied here that follows from our expansion?
Somewhere in the rules of direct declarator
we should branch to a rule that solves a parameter
list. But because our construction was (*func),
we should ignore the identifier in parens after
resolving that it was an identifier from
the direct declarator rule, right?
This is where I don't see how we branch to
a rule that resolves the parameter list.
I don't think it would be the following
rule:
direct-declarator ( parameter-type-list )
unless we consider the expanded identifier
as a direct declarator?
Also, chris torek, if you are reading this,
what data structure would you recommend for
representing this? I read an older
article by you that describes this process
as being in factored form. How do you recommend
to factor it all programmatically?