role of semicolon

M

Merrill & Michele

Mike Wahler said:
And if you want to include 'compound statement' and
a function body qualifies as one, then add one to
each of the above.

If A then A. pete has to have something to say about this. MPJ
 
K

Keith Thompson

E. Robert Tisdale said:
Keith said:
Mike Wahler writes:
[...]
A declaration is a statement.
No, it isn't, according to the grammar in the standard.
A "statement" can be any of the following:
labeled-statement
compound-statement
expression-statement
selection-statement
iteration-statement
jump-statement

Honestly Keith,

You remind me of Beetle Bailey's friend Zero.

You remind me of E. Robert Tisdale. Oh, wait ...
You take the statements in the standard
just a little too literally.

Not in this case.
According to
the American Heritage Dictionary of the English language
[...]

In C, statements and declarations are two different things. Both are
technical terms; the definitions in an English dictionary are not
particularly relevant. Using the terms loosely makes it difficult or
impossible to communicate.

And I think you know that.

In C90, declarations must precede statements within a compound
statement; in C99, they can be mixed.

If you didn't know that declarations and statements are two different
things, you wouldn't have any way of knowing what that statement
means. (Note that I've used the word "statement" here both in its
technical C sense and in its common English sense; the distinction is
clear from context.)

If I refer to a "character" in the context of a C program, are you
going to think I'm talking about Hamlet?
 
A

Alex Fraser

Lawrence Kirby said:
Interestingly this is an example (and the only one) of when a compound
statement ISN'T a statement. Check the grammar.

I understand why you say that (of course, I wrote my previous post with the
grammar in front of me: I have a good memory, but not /that/ good :). I
considered that you can look at this way: a recogniser for a statement would
accept a compound-statement, therefore a compound-statement is a (kind of)
statement. Perhaps that's not really valid, I'm not sure.

Alex
 
K

Keith Thompson

Dik T. Winter said:
Depends on which way you wish to go in the grammar. A compound-statement
is a specific form of a statement (and has been so since the introduction
of the term in Algol 60). So, by all means, the function body is a
statement of particular form (and that was not the case in Algol 60).
In my opinion when Lawrence wrote that that particular compound-statement
was not a statement, he was wrong.

First, let me say that it's really not a very important question; it's
a trivial issue of interest mostly to annoying pedants like me (and
non-annoying pedants like the rest of you who haven't stopped reading
yet).

Let's look at a simple function definition:

int foo(void)
{
return 42;
}

and see how it's parsed.

The whole thing is a function-definition, which expands to:

declaration-specifiers declarator declaration-list(opt) compound-statement

The sub-parts correspond to "int", "foo(void)", (nothing), and
"{ return 42; }", respectively. (I'm not quite certain about the
first three, but the compound-statement is what we're concerned with
here.)

A compound-statement expands to:

{ block-item-list(opt) }

where a block-item-list is a sequence of one or more declarations or
statements (this is in C99; C90 is a bit different here). Obviously
the '{' and '}' match the '{' and '}' delimiters. The block-item-list
matches the sequence consisting of the single statement "return 42;".

At no point in the parsing process is "{ return 42; }" parsed as a
"statement", even though that same token sequence could be a
"statement" if it appeared in a different context.

Similarly, the token sequence "42;" could be a statement (specifically
an expression-statement) if it appeared in a different context, but it
isn't one here.

Q.E.D. (Quite Easily Done)
 
K

Keith Thompson

In addition to terminating statements and declarations, semicolons are
also part of the grammar of a "for" statement. (And of course they
can appear in character constants, string literals, and comments.)
 
K

Keith Thompson

Merrill & Michele said:
"Mike Wahler"
"Merrill & Michele"
[...]
[OT to Mr. Thompson] Q3) Are the attribution arrows correct? MPJ

The indentation levels seem to be correct, but you're still doing
something odd. It's usual to use at least something like "So-and-so
wrote:" rather than just "So-and-so".

You've also modified Mike Wahler's attribution of your previous
article. His attribution was

]
but you shortened it to just

] "Merrill & Michele"

Why? Are you doing this manually?

As I've mentioned before, you seem to be using Microsoft Outlook
Express. A lot of other people use the same software, and don't seem
to have any trouble with attributions. The software should do it for
you. I don't know what you're doing, or why. And I don't
particularly care, except that it makes your articles even harder to
read than they already are.
 
C

CBFalconer

Merrill said:
.... snip ...

I believe Mr. Kirby refers to a statement such as:
i = 6; ++j;
and calls this a compound statement. I can speculate on how many
statements it is and know that I could get it right if I got two
swings at the pitch. I will drag this forum wildly OT if I start
into English grammar and its inability to express truth about
number, so which is it? MPJ

It is two statements. If enclosed by {} it would be one statement,
which happens to be compound, and to consist of two statements.
 
J

Joona I Palaste

[uses cordless keyboard+mouse for 1st time and wonders how he endured life
before]
I believe Mr. Kirby refers to a statement such as:
i = 6; ++j;
and calls this a compound statement. I can speculate on how many statements
it is and know that I could get it right if I got two swings at the pitch.
I will drag this forum wildly OT if I start into English grammar and its
inability to express truth about number, so which is it? MPJ

The C language (not the C preprocessor) does not group anything by
lines. It considers spaces and newlines as equivalent whitespace.
Therefore two statements on the same line is the same thing as two
consecutive lines with one statement on each.
This also means that i = 6; ++j; is two statements, not a compound
statement.
As has been said before, if you want BASIC, you know where to find it.
 
M

Mike Wahler

Keith Thompson said:
In addition to terminating statements and declarations, semicolons are
also part of the grammar of a "for" statement.

I can't believe I forgot about 'for' loops.

Time for a nap (or a drink, or... ) :)
(And of course they
can appear in character constants, string literals, and comments.)

I thought about those, but discarded them, since in
such contexts, the're not being used as part of
the language itself (I suppose someone will
disagree with that, though. :))

Btw I move that we change the title of this thread to
Much Ado About Nothing; :)



-Mike
 
K

Keith Thompson

I've thought of a simpler argument in the debate over whether the
compound-statement in a function-definition is a statement.

Some excerpts from the C99 grammar:

statement:
labeled-statement
compound-statement
expression-statement
selection-statement
iteration-statement
jump-statement

compound-statement:
{ block-item-list(opt) }

function-definition:
declaration-specifiers declarator declaration-list(opt) compound-statement

Clearly a compound-statement is a kind of statement if it appears in a
statement context. If it appears in a different context, the only
real basis for claiming that it's a "statement" is that the name of
the construct ends in "-statement".

Consider the following grammar:

statement:
labeled-statement
block
expression-statement
selection-statement
iteration-statement
jump-statement

block:
{ block-item-list(opt) }

function-definition:
declaration-specifiers declarator declaration-list(opt) block

The only change is that I've relaced the term "compound-statement"
with "block". This grammar describes exactly the same language as the
actual C99 grammar. But if the C grammar were defined this way, it
would be obvous that the block in a function-definition is *not* a
statement; it's just a block.

Geerically, it's natural to assume that if the grammar refers to
something as an ADJECTIVE-NOUN, an ADJECTIVE-NOUN must be a kind of
NOUN. That's common sense based on the rules of English, but the C
grammar isn't written in English, even though it uses a lot of English
and English-like words. In this case, there's a specific definition
of what a NOUN is, and the definition shows that not all
ADJECTIVE-NOUNs are NOUNs. (Even in plain English, a silverfish is
not a fish.)

I think we have to assume that "compound-statement" is a single term
defined by the grammar, not a phrase to be interpreted according to
its parts. It looks like a phrase, and it was obviously chosen to
imply that a compound-statement is a kind of statement, but this is
overridden by the explicit definition that says it isn't.

(And if ERT wanted to give me a hard time for being too literal, this
would have been a good opportunity.)
 
M

Merrill & Michele

Joona I Palaste said:
Merrill & Michele said:
'{'
to count
that
[uses cordless keyboard+mouse for 1st time and wonders how he endured life
before]
I believe Mr. Kirby refers to a statement such as:
i = 6; ++j;
and calls this a compound statement. I can speculate on how many statements
it is and know that I could get it right if I got two swings at the pitch.
I will drag this forum wildly OT if I start into English grammar and its
inability to express truth about number, so which is it? MPJ

The C language (not the C preprocessor) does not group anything by
lines. It considers spaces and newlines as equivalent whitespace.
Therefore two statements on the same line is the same thing as two
consecutive lines with one statement on each.
This also means that i = 6; ++j; is two statements, not a compound
statement.
As has been said before, if you want BASIC, you know where to find it.

This might be much ado about nothing, but I didn't know that the language
considers whitespace and newlines as equivalent in this context. MPJ
 
J

Joona I Palaste

This might be much ado about nothing, but I didn't know that the language
considers whitespace and newlines as equivalent in this context. MPJ

Well, now you do.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"You can pick your friends, you can pick your nose, but you can't pick your
relatives."
- MAD Magazine
 
M

Mike Wahler

Merrill & Michele said:
This might be much ado about nothing, but I didn't know that the language
considers whitespace and newlines as equivalent in this context. MPJ

Context doesn't matter in this case. The newline character is
specifically defined as a member of the set known as 'whitespace
characters'.

-Mike
 
M

Merrill & Michele

Mike Wahler said:
Context doesn't matter in this case. The newline character is
specifically defined as a member of the set known as 'whitespace
characters'.

Another nuance. What all belongs to whitespace char family? MPJ
 
D

Dik T. Winter

> Clearly a compound-statement is a kind of statement if it appears in a
> statement context. If it appears in a different context, the only
> real basis for claiming that it's a "statement" is that the name of
> the construct ends in "-statement".

Wait a moment. Is 42 an expression?

My reasoning is *not* based on the name, it is based on the production
rules. "statement" is the only production rule that produces
"compound-statement" without anything else. And that is why I say that
it is a particular form of a statement. Your point would have been
stronger when the syntax had been:
function-definition:
declaration-specifiers declarator declaration-list(opt) function-body
function-body:
compound-statement
 
M

Merrill & Michele

pete said:
(space, horizontal tab, new-line, vertical tab, and form-feed)

I'm always glad when pete is the man who has the back of the man who needs
to use hemorrhoidal creme. These must have representations not linked to
integers. I threw away K&R2 today. MPJ
 
M

Merrill & Michele

Dik T. Winter said:
...

Wait a moment. Is 42 an expression?

My reasoning is *not* based on the name, it is based on the production
rules. "statement" is the only production rule that produces
"compound-statement" without anything else.

Dat is a violation of Engishgrammatik. You need something unidexed here.
(Chomsky, Kerek, bla, bla )

And that is why I say that
it is a particular form of a statement. Your point would have been
stronger when the syntax had been:
function-definition:
declaration-specifiers declarator declaration-list(opt) function-body
function-body:
compound-statement
http://www.cwi.nl/~dik/

Wie kann man mit nem Keyboard snakken? MJP
 
J

Joona I Palaste

Merrill & Michele said:
I'm always glad when pete is the man who has the back of the man who needs
to use hemorrhoidal creme. These must have representations not linked to
integers. I threw away K&R2 today. MPJ

I actually had a dream about you last night. Well, you didn't actually
appear in my dream. I was talking with other clc regulars (I don't
remember who) and we talked about you sometimes making sense and
sometimes not.
Are you one or two people? You name yourself as "Merrill & Michele" in
your posts. Is it Merrill or Michele who writes here?
 
K

Keith Thompson

Dik T. Winter said:
Wait a moment. Is 42 an expression?

Yes, why do you ask?
My reasoning is *not* based on the name, it is based on the production
rules. "statement" is the only production rule that produces
"compound-statement" without anything else. And that is why I say that
it is a particular form of a statement. Your point would have been
stronger when the syntax had been:
function-definition:
declaration-specifiers declarator declaration-list(opt) function-body
function-body:
compound-statement

I don't follow your reasoning. In particular, I don't see how the
"without anything else" is relevant.
 

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

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,413
Latest member
KeiraLight

Latest Threads

Top