473,799 Members | 3,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Should use of goto completely avoided in programs?

I wrote a program for removing comment from C source file for which
i...
1.first constructed a DFA
2.used goto statement to write a program.

now it was very easy to model DFA using goto & i suppose it was also
efficient.

so was the use of goto right here?

thanx

Sumit
PUCSD

Nov 15 '05
17 2314
In article <kf************ *@alumnus.calte ch.edu>,
Tim Rentsch <tx*@alumnus.ca ltech.edu> wrote:

Incidentally, the removal of comments from C source cannot,
strictly speaking, be done with just a finite state machine
(aka DFA). Additional state (in principle unbounded) is
needed. (I'll just leave this topic here, without saying
why, in case some comp.lang.c readers would enjoy figuring
that out on their own.)


/\
\
\
\
* Are you referring to comments like this? *\
\
\
\
/

Nov 15 '05 #11
an******@exampl e.com (Anonymous 7843) writes:
In article <kf************ *@alumnus.calte ch.edu>,
Tim Rentsch <tx*@alumnus.ca ltech.edu> wrote:

Incidentally, the removal of comments from C source cannot,
strictly speaking, be done with just a finite state machine
(aka DFA). Additional state (in principle unbounded) is
needed. (I'll just leave this topic here, without saying
why, in case some comp.lang.c readers would enjoy figuring
that out on their own.)


/\
\
\
\
* Are you referring to comments like this? *\
\
\
\
/


Yes. The start of that comment needs unbounded
lookahead to tell that it's a comment rather than,
for example, a '/=' operator.
Nov 15 '05 #12
"Tim Rentsch" <tx*@alumnus.ca ltech.edu> wrote in message
news:kf******** *****@alumnus.c altech.edu...
an******@exampl e.com (Anonymous 7843) writes:
In article <kf************ *@alumnus.calte ch.edu>,
Tim Rentsch <tx*@alumnus.ca ltech.edu> wrote:
>
> Incidentally, the removal of comments from C source cannot,
> strictly speaking, be done with just a finite state machine
> (aka DFA). Additional state (in principle unbounded) is
> needed. (I'll just leave this topic here, without saying
> why, in case some comp.lang.c readers would enjoy figuring
> that out on their own.)


/\
\
\
\
* Are you referring to comments like this? *\
\
\
\
/


Yes. The start of that comment needs unbounded
lookahead to tell that it's a comment rather than,
for example, a '/=' operator.


Uh, no. A comment is syntactically equivalent to a single
space character, which turns any comment of the form
"//**/=" into "/ =".

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Nov 15 '05 #13
"P.J. Plauger" <pj*@dinkumware .com> writes:
"Tim Rentsch" <tx*@alumnus.ca ltech.edu> wrote in message
news:kf******** *****@alumnus.c altech.edu...
an******@exampl e.com (Anonymous 7843) writes:
In article <kf************ *@alumnus.calte ch.edu>,
Tim Rentsch <tx*@alumnus.ca ltech.edu> wrote:
>
> Incidentally, the removal of comments from C source cannot,
> strictly speaking, be done with just a finite state machine
> (aka DFA). Additional state (in principle unbounded) is
> needed. (I'll just leave this topic here, without saying
> why, in case some comp.lang.c readers would enjoy figuring
> that out on their own.)

/\
\
\
\
* Are you referring to comments like this? *\
\
\
\
/


Yes. The start of that comment needs unbounded
lookahead to tell that it's a comment rather than,
for example, a '/=' operator.


Uh, no. A comment is syntactically equivalent to a single
space character, which turns any comment of the form
"//**/=" into "/ =".


Right, however that isn't the case I was talking
about. I meant this one:

/\
\
\
\
\
\
=

which looks like it might be a comment until
the scan gets to the '=' character.
Nov 15 '05 #14
In article <kf************ *@alumnus.calte ch.edu>,
Tim Rentsch <tx*@alumnus.ca ltech.edu> wrote:


an******@exampl e.com (Anonymous 7843) writes:
In article <kf************ *@alumnus.calte ch.edu>,
Tim Rentsch <tx*@alumnus.ca ltech.edu> wrote:

Incidentally, the removal of comments from C source cannot,
strictly speaking, be done with just a finite state machine
(aka DFA). Additional state (in principle unbounded) is
needed. (I'll just leave this topic here, without saying
why, in case some comp.lang.c readers would enjoy figuring
that out on their own.)


/\
\
\
\
* Are you referring to comments like this? *\
\
\
\
/


Yes. The start of that comment needs unbounded
lookahead to tell that it's a comment rather than,
for example, a '/=' operator.


Unbounded lookahead is not the same as unbounded state. The repetition
of backslash/newline is two states no matter how long it goes on for
and is well within the abilities of a DFA.

However, catering to backslash/newline for every possible token
is a tedious way to implement a lexer. One might prefer to paste the
backslash/newlines together in an early phase, even before removing
comments.
Nov 15 '05 #15
an******@exampl e.com (Anonymous 7843) writes:
In article <kf************ *@alumnus.calte ch.edu>,
Tim Rentsch <tx*@alumnus.ca ltech.edu> wrote:


an******@exampl e.com (Anonymous 7843) writes:
In article <kf************ *@alumnus.calte ch.edu>,
Tim Rentsch <tx*@alumnus.ca ltech.edu> wrote:
>
> Incidentally, the removal of comments from C source cannot,
> strictly speaking, be done with just a finite state machine
> (aka DFA). Additional state (in principle unbounded) is
> needed. (I'll just leave this topic here, without saying
> why, in case some comp.lang.c readers would enjoy figuring
> that out on their own.)

/\
\
\
\
* Are you referring to comments like this? *\
\
\
\
/


Yes. The start of that comment needs unbounded
lookahead to tell that it's a comment rather than,
for example, a '/=' operator.


Unbounded lookahead is not the same as unbounded state. The repetition
of backslash/newline is two states no matter how long it goes on for
and is well within the abilities of a DFA.

However, catering to backslash/newline for every possible token
is a tedious way to implement a lexer. One might prefer to paste the
backslash/newlines together in an early phase, even before removing
comments.


I think you may have missed the significance of the context here.
We weren't talking about writing a lexer. The requirement is for
a program to remove comments from C source code, and except for
removing comments leaves the original source completely intact
(not counting possibly inserting spaces to preserve the token
boundaries around the removed comments).

In this context it's important to know how many \<NL> pairs have
been skipped over, because they may need to be output if they
don't belong to a comment. Needing that count is what changes
the problem to one that can't be done with a finite state
machine.
Nov 15 '05 #16
In article <kf************ *@alumnus.calte ch.edu>,
Tim Rentsch <tx*@alumnus.ca ltech.edu> wrote:

I think you may have missed the significance of the context here.
We weren't talking about writing a lexer. The requirement is for
a program to remove comments from C source code, and except for
removing comments leaves the original source completely intact
(not counting possibly inserting spaces to preserve the token
boundaries around the removed comments).

In this context it's important to know how many \<NL> pairs have
been skipped over, because they may need to be output if they
don't belong to a comment. Needing that count is what changes
the problem to one that can't be done with a finite state
machine.


You have piqued my curiousity. I'm going to read about flex some more
and have a go at writing a proper comment-removal thingy. I think the
trailing context feature would be sufficient to decide whether or not
to emit backslash/newline, but I'm going to try it out before digging
myself any deeper into the hole.
Nov 15 '05 #17
an******@exampl e.com (Anonymous 7843) writes:
In article <kf************ *@alumnus.calte ch.edu>,
Tim Rentsch <tx*@alumnus.ca ltech.edu> wrote:

I think you may have missed the significance of the context here.
We weren't talking about writing a lexer. The requirement is for
a program to remove comments from C source code, and except for
removing comments leaves the original source completely intact
(not counting possibly inserting spaces to preserve the token
boundaries around the removed comments).

In this context it's important to know how many \<NL> pairs have
been skipped over, because they may need to be output if they
don't belong to a comment. Needing that count is what changes
the problem to one that can't be done with a finite state
machine.


You have piqued my curiousity. I'm going to read about flex some more
and have a go at writing a proper comment-removal thingy. I think the
trailing context feature would be sufficient to decide whether or not
to emit backslash/newline, but I'm going to try it out before digging
myself any deeper into the hole.


I expect the trailing context feature is sufficient to resolve
the question. Of course, using the trailing context feature
already (in the general case) makes the program exceed what a
finite state machine can do: the trailing context lookahead has
to remember where to continue scanning after checking the
trailing context, and remembering where to go back to takes (in
the theoretical sense) unbounded memory.
Nov 15 '05 #18

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

Similar topics

303
17794
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
22
510
by: Samee Zahur | last post by:
In a recent thread, I saw the topic of goto coming up, so here's a question: With a background of asm langs, I know exactly why goto is to be avoided. But does anyone know of a good way for "break"ing out of nested loops? Say, breaking out by 2 levels out of the third nesting? By "good way" I mean one without goto (like PHP has "break 2;" or "continue 2;") Samee
45
2732
by: Debashish Chakravarty | last post by:
K&R pg.66 describes two situations when using goto makes sense. Has anyone here come across situations where using goto provided the most elegant solution. -- http://www.kashmiri-pandit.org/atrocities/index.html
64
3407
by: Morgan Cheng | last post by:
Hi All, I was taught that argument valuse is not supposed to be changed in function body. Say, below code is not good. void foo1(int x) { x ++; printf("x+1 = %d\n", x); } It should be "refactor-ed" to be
28
2732
by: Vishal Naidu | last post by:
i m new to the C world... i ve been told by my instructors not to use goto stmt.. but no one could give me a satisfactory answer as to why it is so.. plz help me out of this dilemma, coz i use a lot of goto in my codes....
13
8465
by: Kartic | last post by:
Hi, Is it good practice using GOTO in .NET application? Please advice. Thanks, Kartic
17
2617
by: SoftEast | last post by:
Hi Buddies, I have read a lot of stuffs regarding not using GOTO statements to opt a good programming style http://david.tribble.com/text/goto.html]. Can anybody give a particular lines of code which shows harmfullness of GOTO. SoftEast...
11
3419
by: =?Utf-8?B?Um9nZXIgVHJhbmNoZXo=?= | last post by:
Hello, I have a question about the infamous GOTO statement and the way to return a result from a sub: I have a sub that has to make some calls to external COM methods, and because these methods can fail I have to check them to be running ok, like this:
59
5072
by: raashid bhatt | last post by:
why are GOTO's not used they just a simple JMP instructions what's bad about them
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10470
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10023
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
9067
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
7561
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
6803
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();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.