Paulo Matos wrote:
Victor Bazarov wrote:
>Paulo Matos wrote:
>>I'm trying to work out a parser for function declarations but it
turns out that it is harder than I initially thought.
I'm looking at 3rd Ed of Stroustrup, page 808.
I'm trying to parse something like:
int foo(int, int);
const double *xpto(mytype *, mytype &) const;
But I'm not being able to find my way around the grammar.
First, I can't find a function-declaration non-terminal. The closest
is function-definition, but that will need the function-body, which
cannot end up with ;.
It can within a class definition (unfortunately).
I thought I was asking a specific question, sorry.
Don't worry about it. It's my fault. I didn't see it.
In fact, what I
wanted to know is which is the non-terminal
I guess I am not sure what "non-terminal" you're referring to. I am
not a grammar pro, and C++ standard doesn't have that term.
which start function
declarations inside class definitions. Problem is that looking by the
grammar I can't understand how it copes with
class foo {
int xpto();
};
for example. This is because the only thing I can find is
function-definition which cannot end up with ; [see grammar], so it
won't parse
int xpto();
The grammar says that the class definition contains a potentially empty
set of 'member-specifications' inside the curly braces. Each
'member-specification' is a sequence of 'member-declarations' (possibly
preceded by an 'access-specifier'). Each 'member-declaration' ends
with a semicolon unless it's a 'function definition' (after which the
semicolon is optional), or it's a 'using-declaration', or it's
a 'template-declaration'. A 'using-declaration' shall end with
a semicolon. You can probably arrive at a semicolon or a curly brace
for a 'template-declaration' as well.
Now, or I am missing a non-terminal symbol or I'm not reading
function-definition correctly.
You should be reading a 'member-declaration' inside a class definition.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask