Without semicolons

D

Dan Pop

In said:
A compiler invoked with such a flag is *not* a conforming C
implementation.

I can't see *any* requirement that the output is a C program, so Case's
solution is perfectly valid, with a couple of minor fixes:
-DNOT_A_SEMICOLON=";" (the Unix shell will treat an unprotected semicolon
as a command separator, which is not what you want).

However, the program specification is so flawed that an even simpler
solution is possible: reproduce the input with no changes at all. It
works for *a* C program that doesn't contain any semicolons in the first
place ;-)

Neither solution works if we replace "a C program" by "any C program",
and "for a program" by "for a C program", but then I seriously doubt
that *any* solution exists for this program specification, except for the
following cheat: -D__NOT_A_SEMICOLON=";". No correct C program can
use the __NOT_A_SEMICOLON identifier and a compiler invoked with this
option is still a conforming C compiler ;-) Any correct C program
will be converted to a C program invoking undefined behaviour,
but that will work as expected if compiled by a conforming compiler
invoked with the "magic" option.

Dan
 
J

Jeremy Yallop

Dan said:
I can't see *any* requirement that the output is a C program, so Case's
solution is perfectly valid, with a couple of minor fixes:
-DNOT_A_SEMICOLON=";" (the Unix shell will treat an unprotected semicolon
as a command separator, which is not what you want).

No, this doesn't handle semicolons in strings.
However, the program specification is so flawed that an even simpler
solution is possible: reproduce the input with no changes at all. It
works for *a* C program that doesn't contain any semicolons in the first
place ;-)

Cute, but misguided. Admittedly "a" is in some respect ambiguous
between "any" and "a certain", but it can't be reasonably interpreted
as "a certain" in the text at the top of this post. When K&R write

Write a program that reads a C program and prints in alphabetical
order each group of variable names that are identical in the first
6 characters [...] (Exercise 6.2)

do you think that they are asking for a solution that only works on a
particular program of your choosing? There are plenty more such
examples. I think "so flawed" is pretty unreasonable: I don't think
you're in any doubt as to what the specification means.

Jeremy.
 
D

Dan Pop

In said:
No, this doesn't handle semicolons in strings.

This is true, but unimportant: handling character and string literals is
a doable and relatively minor task.
However, the program specification is so flawed that an even simpler
solution is possible: reproduce the input with no changes at all. It
works for *a* C program that doesn't contain any semicolons in the first
place ;-)

Cute, but misguided. Admittedly "a" is in some respect ambiguous
between "any" and "a certain", but it can't be reasonably interpreted
as "a certain" in the text at the top of this post. When K&R write

Write a program that reads a C program and prints in alphabetical
order each group of variable names that are identical in the first
6 characters [...] (Exercise 6.2)

do you think that they are asking for a solution that only works on a
particular program of your choosing? There are plenty more such
examples. I think "so flawed" is pretty unreasonable: I don't think
you're in any doubt as to what the specification means.

My doubts are irrelevant. The fact is that your specification *can* be
interpreted as handling a single C program and generating a Fortran
program as output. And if I want to be really picky, I can point out that
according to the C standard, pretty much anything counts as a C program :)
That's why I usually use the term "correct C program".

Dan
 
T

Thomas Matthews

Martin said:
Huh? I seriously doubt that. :)

Martin

Actually, many replies have been posted. Some suggestions,
some actual answers.

http://www.google.com/groups?as_q=w...images&as_ugroup=comp.lang.c&lr=&num=50&hl=en


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
A

Arthur J. O'Dwyer

(s/SIMICOLON/SEMICOLON/ of course.)
This is true, but unimportant: handling character and string literals is
a doable and relatively minor task.

I considered this point when I wrote the "print a semicolon without
using a semicolon" program (which BTW it only now occurs to me could
have been a lot shorter!). As far as I can tell, there is *no* way to
produce the sstring literal ";" nor the character literal ';' in a
confroming C program, without using at least one semicolon.
(Character-encoding-specific hacks excluded, of course.)
Does Dan Pop see something I don't? (That's a common occurrence,
but it strikes me as unlikely in this case.)

-Arthur
 
C

Case

Arthur said:
(s/SIMICOLON/SEMICOLON/ of course.)




I considered this point when I wrote the "print a semicolon without
using a semicolon" program (which BTW it only now occurs to me could
have been a lot shorter!). As far as I can tell, there is *no* way to
produce the sstring literal ";" nor the character literal ';' in a

(s/sstring/string/ of course.)
confroming C program, without using at least one semicolon.

(s/confroming/conforming/ of course.)
(Character-encoding-specific hacks excluded, of course.)
Does Dan Pop see something I don't? (That's a common occurrence,
but it strikes me as unlikely in this case.)

-Arthur

:) Kees
 
D

Dan Pop

(s/SIMICOLON/SEMICOLON/ of course.)


I considered this point when I wrote the "print a semicolon without
using a semicolon" program (which BTW it only now occurs to me could
have been a lot shorter!). As far as I can tell, there is *no* way to
produce the sstring literal ";" nor the character literal ';' in a
confroming C program, without using at least one semicolon.
(Character-encoding-specific hacks excluded, of course.)
Does Dan Pop see something I don't? (That's a common occurrence,
but it strikes me as unlikely in this case.)

Since you have the NOT_A_SEMICOLON macro, you can build the ";" string
literal using the method documented in the FAQ. Once you have this
string, it is trivial to obtain the value of the ';' character. No
character set dependencies involved.

Dan
 

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
473,773
Messages
2,569,594
Members
45,113
Latest member
Vinay KumarNevatia
Top