473,796 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Without semicolons

Write a program that takes a C program in source form as input and
prints the source code for a program with equivalent behaviour, but
without semicolons, on standard output.

Please note that I'm not interested in the DMS Software Reengineering
Toolkit.

Jeremy.
Nov 14 '05
27 2015
In <cu************ *@zero-based.org> Martin Dickopp <ex************ ****@zero-based.org> writes:
Case <no@no.no> writes:
Jeremy Yallop wrote:
Write a program that takes a C program in source form as input and
prints the source code for a program with equivalent behaviour, but
without semicolons, on standard output.


Replace all semicolons with NOT_A_SEMICOLON between some white space
and compile with the appropriate-something-like -DNOT_A_SIMICOLO N=;
flag :-)


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_SEMICOLO N=";" (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_SEMICO LON=";". No correct C program can
use the __NOT_A_SEMICOL ON 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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #21
Dan Pop wrote:
In <cu************ *@zero-based.org> Martin Dickopp <ex************ ****@zero-based.org> writes:
Case <no@no.no> writes:
Jeremy Yallop wrote:
Write a program that takes a C program in source form as input and
prints the source code for a program with equivalent behaviour, but
without semicolons, on standard output.

Replace all semicolons with NOT_A_SEMICOLON between some white space
and compile with the appropriate-something-like -DNOT_A_SIMICOLO N=;
flag :-)
A compiler invoked with such a flag is *not* a conforming C
implementatio n.


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_SEMICOLO N=";" (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.
Nov 14 '05 #22
In <sl************ *******@kaje.cl .cam.ac.uk> Jeremy Yallop <je****@jdyallo p.freeserve.co. uk> writes:
Dan Pop wrote:
In <cu************ *@zero-based.org> Martin Dickopp <ex************ ****@zero-based.org> writes:
Case <no@no.no> writes:
Jeremy Yallop wrote:
> Write a program that takes a C program in source form as input and
> prints the source code for a program with equivalent behaviour, but
> without semicolons, on standard output.

Replace all semicolons with NOT_A_SEMICOLON between some white space
and compile with the appropriate-something-like -DNOT_A_SIMICOLO N=;
flag :-)

A compiler invoked with such a flag is *not* a conforming C
implementati on.


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_SEMICOLO N=";" (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.


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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #23
Martin Dickopp wrote:
Thomas Matthews <Th************ *************@s bcglobal.net> writes:

Jeremy Yallop wrote:
Write a program that takes a C program in source form as input and
prints the source code for a program with equivalent behaviour, but
without semicolons, on standard output. Please note that I'm not
interested in the DMS Software Reengineering Toolkit.


The answer has been posted here many times.

Huh? I seriously doubt that. :)

Martin


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

http://www.google.com/groups?as_q=wi...=&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.l earn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #24
Thomas Matthews <Th************ *************** *@sbcglobal.net > writes:
Martin Dickopp wrote:
Thomas Matthews <Th************ *************@s bcglobal.net> writes:
Jeremy Yallop wrote:

Write a program that takes a C program in source form as input and
prints the source code for a program with equivalent behaviour, but
without semicolons, on standard output. Please note that I'm not
intereste d in the DMS Software Reengineering Toolkit.

The answer has been posted here many times.

Huh? I seriously doubt that. :)


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

http://www.google.com/groups?as_q=wi...=&num=50&hl=en


A lot of examples of programs without semicolon have been posted, but
that is not at all what Jeremy asked about. Unless I adopt Dan's
interpretation of "a C program", I still don't see anything which comes
close to Jeremy's specification.

Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Nov 14 '05 #25

On Wed, 12 May 2004, Dan Pop wrote:

Jeremy Yallop <je****@jdyallo p.freeserve.co. uk> writes:
Case <no@no.no> writes:
> Jeremy Yallop wrote:
>> Write a program that takes a C program in source form as input and
>> prints the source code for a program with equivalent behaviour, but
>> without semicolons, on standard output.
>
> Replace all semicolons with NOT_A_SEMICOLON between some white space
> and compile with the appropriate-something-like -DNOT_A_SIMICOLO N=;

(s/SIMICOLON/SEMICOLON/ of course.)
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.


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
Nov 14 '05 #26
Arthur J. O'Dwyer wrote:
On Wed, 12 May 2004, Dan Pop wrote:
Jeremy Yallop <je****@jdyallo p.freeserve.co. uk> writes:
>Case <no@no.no> writes:
>
>>Jeremy Yallop wrote:
>>
>>>Write a program that takes a C program in source form as input and
>>>prints the source code for a program with equivalent behaviour, but
>>>withou t semicolons, on standard output.
>>
>>Replace all semicolons with NOT_A_SEMICOLON between some white space
>>and compile with the appropriate-something-like -DNOT_A_SIMICOLO N=;

(s/SIMICOLON/SEMICOLON/ of course.)

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.

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
Nov 14 '05 #27
In <Pi************ *************** ********@unix41 .andrew.cmu.edu > "Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> writes:

On Wed, 12 May 2004, Dan Pop wrote:

Jeremy Yallop <je****@jdyallo p.freeserve.co. uk> writes:
>>> Case <no@no.no> writes:
>>>> Jeremy Yallop wrote:
>>>>> Write a program that takes a C program in source form as input and
>>>>> prints the source code for a program with equivalent behaviour, but
>>>>> without semicolons, on standard output.
>>>>
>>>> Replace all semicolons with NOT_A_SEMICOLON between some white space
>>>> and compile with the appropriate-something-like -DNOT_A_SIMICOLO N=;
(s/SIMICOLON/SEMICOLON/ of course.)
>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.


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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #28

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2155
by: Mage | last post by:
Hello, I amafraid of I will stop using semicolons in other languages after one or two months of python. However I see that python simply ignores the semicolons atd the end of the lines. What's your advice? I don't want to write full-of-typo php scripts but I see the logic of the python syntax too. Mage
1
1806
by: jjbutera | last post by:
How do I escape these? The backslash doesn't seem to be working.
4
2954
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400, like DOS, uses memory-mapped display, two bytes per character (one char byte and one attribute byte). We can get the screen offset allright, and I've written a javascript which does the math to convert the offset into row/col (i.e. left, top)...
9
2189
by: Jukka K. Korpela | last post by:
I noticed that Internet Explorer (6.0, on Win XP SP 2, all fixes installed) incorrectly renders e.g. &harr &euro &Omega literally and not as characters denoted by the entities, but if a semicolon is appended to each of the entity references, they work. I'm pretty sure that previous versions of IE rendered them by the specifications. I first thought this has something to do with XML (i.e. maybe IE pretends to play a little bit of XML...
17
2348
by: subnet | last post by:
I'm not a C expert, but I've seen this topic discussed in the newsgroup several times. What's the deal with writing such programs? Why are they considered so interesting? Thanks
4
1412
by: Waxhead | last post by:
Hi folks, First of all I'm new to newsgroups so please don't kill me in case I'm breaking any rules , but if you really have to make it quick and painfull ;) What is actually propper hehaviour of Snippet 1 ? as I understand it the result should be the same as snippet 2. (but it isn't at least with my compiler). I expect snippet 1 to work like this: if then for and function() else just function() or perhaps a bit clearer:
3
1555
by: Stefan Mueller | last post by:
I've a web page with several input boxes. After the user clicks 'submit' I insert these data into my MySQL database. This worked for several months perfect. But today a user entered the street name Route d'Yverdon 59 unfortunately the data has not been inserted into my MySQL database because of the apostroph (') in the name of the street. I've no idea how to deal with this problem.
12
2543
by: feel | last post by:
Hi,All I am sure it's an old question. But I just find a interesting design about this: Polymorphism without virtual function in a C++ class. My solution is for some special case, trust me, very special. 1 single root class tree 2 the leaf(lowest level) classes are sealed which means we should not inherite class from them. 3 PImpl idiom. There is only one data mumber in root class and there is no any other data mumber in child class and...
0
9533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10019
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9057
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.