Grammatical analysis of C++

  • Thread starter Steven T. Hatton
  • Start date
S

Steven T. Hatton

I often find myself at a loss to find the correct words to identify the
parts of a C++ statement. I know you can pick up a lot by reading the
Standard. That may indeed be the best available route to take. Is there
any more pedagogical text that deals with C++ in fromal grammatical terms?
On simple example that prompted me to post this is as follows:

typedef what_the_heck_is_this typedef_name;

What is that thing in the middle called? How should that statement be
deconstructed?
 
D

daniel.w.gelder

I don't know what it's called, but if I leave it out, I'll catch hell
from my wife! Seriously, Martha's great, but the other day when my
pastor told me that people who practice a certain sexual position are
going to hell -- I suggested she try it -- with her boyfriend!
 
O

Old Wolf

Steven said:
I often find myself at a loss to find the correct words to identify the
parts of a C++ statement. I know you can pick up a lot by reading the
Standard. That may indeed be the best available route to take. Is there
any more pedagogical text that deals with C++ in fromal grammatical terms?
On simple example that prompted me to post this is as follows:

typedef what_the_heck_is_this typedef_name;

What is that thing in the middle called?

You could use /type name/ to informally refer to your
"what_the_heck_is_this".

The type name and the identifier together are called a
/type-specifier/.
How should that statement be deconstructed?

The C++ language grammar is in Appendix A of the Standard.
It is more complicated than your example, so that it can
deal with things like:
typedef int x[5];
or
typedef typename foo::bar baz;
or function pointer typedefs, etc.
 
J

John Carson

Steven T. Hatton said:
I often find myself at a loss to find the correct words to identify
the parts of a C++ statement. I know you can pick up a lot by
reading the Standard. That may indeed be the best available route to
take. Is there any more pedagogical text that deals with C++ in
fromal grammatical terms? On simple example that prompted me to post
this is as follows:

typedef what_the_heck_is_this typedef_name;

What is that thing in the middle called? How should that statement be
deconstructed?

Can't help you with the general grammar thing, but typedefs basically work
the same as variable declarations. Declare a variable, put typedef at the
beginning, and your variable name is now a type name giving the type of the
variable you previously declared.
 
S

Steven T. Hatton

Old said:
Steven said:
I often find myself at a loss to find the correct words to identify the
parts of a C++ statement. I know you can pick up a lot by reading the
Standard. That may indeed be the best available route to take. Is there
any more pedagogical text that deals with C++ in fromal grammatical
terms? On simple example that prompted me to post this is as follows:

typedef what_the_heck_is_this typedef_name;

What is that thing in the middle called?

You could use /type name/ to informally refer to your
"what_the_heck_is_this".

The type name and the identifier together are called a
/type-specifier/.
How should that statement be deconstructed?

The C++ language grammar is in Appendix A of the Standard.
It is more complicated than your example, so that it can
deal with things like:
typedef int x[5];
or
typedef typename foo::bar baz;
or function pointer typedefs, etc.
Theres always this:

template <class T, class Container = deque<T> >
class stack {
public:
typedef typename Container::value_type value_type;
//...
};
 
G

Greg

Steven said:
I often find myself at a loss to find the correct words to identify the
parts of a C++ statement. I know you can pick up a lot by reading the
Standard. That may indeed be the best available route to take. Is there
any more pedagogical text that deals with C++ in fromal grammatical terms?
On simple example that prompted me to post this is as follows:

typedef what_the_heck_is_this typedef_name;

What is that thing in the middle called? How should that statement be
deconstructed?
--

The thing in the middle is formally called the "type-specifier" which
could be any one of the following:

simple-type-specifier
class-specifier
enum-specifier
elaborated-type-specifier
cv-qualifier

and of course each of those can be further broken down into...

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top