Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C Style commenting
#28
Quote:Your FSM sounds like a "step sequencer" like computer --- no branching, just set flags.

I've heard the term FSM, but never saw a real life use of it.
*****

You have real life uses of it almost in every compiler. A FSM is the better way to go when you are checking for syntax. Basicly you build a grammar which is used to build a FSM. I'm pretty sure you've learned about Turing Machine, it has much to do with the concept.

In a FSM you have a set of states, and you read a queue composed by symbols. At each state, each posible symbol will lead to a new state, which can be the same state. You can associate actions to states, which is very useful.

To approach this task using a FSM, you could have this set:

[Image: fsm.gif]

Quote:
Moneo Wrote:1) It's possible that /* or */ or // could appear inside of a quoted string, and some quoted strings are delimited by double quotes (") and others by single quotes ('). So every time the program finds one of these supposed comment delimeters, it would have to do several scans to make sure that they were not found within quoted strings, which of course would have to be ignored. This is not as easy as it sounds. Watch out, 'cause the comments themselves could contain either of the quotes or even embedded delimiters themselves.

Well that makes the challenge a little harder then! That way people's entries will vary and I'll be able to judge which program is better.

That would be just bad practice. That is not allowed in C/C++ at all, so this parser would allow files that won't compile.

Anyhow, this can be easily done using a single counter. If you find "/*" add to the counter, if you find "*/" substract from it. When counter = 0 you are outside comments. When counter>0 you are in any nested counter.

Note that if counter < 0 there is an error about unbalanced delimiters.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Messages In This Thread
C Style commenting - by oracle - 01-01-2004, 03:18 AM
C Style commenting - by red_Marvin - 01-01-2004, 03:35 AM
C Style commenting - by oracle - 01-01-2004, 04:16 AM
C Style commenting - by adosorken - 01-01-2004, 05:18 AM
C Style commenting - by Zack - 01-01-2004, 05:52 AM
C Style commenting - by oracle - 01-01-2004, 06:08 AM
C Style commenting - by Plasma - 01-01-2004, 06:16 AM
C Style commenting - by oracle - 01-01-2004, 06:18 AM
C Style commenting - by Plasma - 01-01-2004, 07:45 AM
C Style commenting - by adosorken - 01-01-2004, 08:02 AM
C Style commenting - by Agamemnus - 01-01-2004, 08:29 AM
C Style commenting - by adosorken - 01-01-2004, 08:45 AM
C Style commenting - by Plasma - 01-01-2004, 10:17 AM
C Style commenting - by Anonymous - 01-01-2004, 10:31 AM
C Style commenting - by adosorken - 01-01-2004, 10:46 AM
C Style commenting - by Zack - 01-01-2004, 08:39 PM
C Style commenting - by wildcard - 01-01-2004, 08:46 PM
C Style commenting - by Zack - 01-01-2004, 08:47 PM
C Style commenting - by Fling-master - 01-01-2004, 08:49 PM
C Style commenting - by Moneo - 01-02-2004, 06:52 AM
C Style commenting - by na_th_an - 01-02-2004, 06:56 AM
C Style commenting - by Moneo - 01-02-2004, 07:06 AM
C Style commenting - by na_th_an - 01-02-2004, 07:13 AM
C Style commenting - by Moneo - 01-02-2004, 07:40 AM
C Style commenting - by na_th_an - 01-02-2004, 07:48 AM
C Style commenting - by Moneo - 01-02-2004, 07:55 AM
C Style commenting - by oracle - 01-02-2004, 08:06 AM
C Style commenting - by na_th_an - 01-02-2004, 08:26 AM
C Style commenting - by oracle - 01-02-2004, 10:01 AM
C Style commenting - by na_th_an - 01-02-2004, 10:27 AM
C Style commenting - by oracle - 01-02-2004, 10:30 AM
C Style commenting - by adosorken - 01-02-2004, 10:31 AM
C Style commenting - by Mango - 01-02-2004, 03:37 PM
C Style commenting - by Rhiannon - 01-02-2004, 04:46 PM
C Style commenting - by LooseCaboose - 01-04-2004, 12:30 PM
C Style commenting - by Agamemnus - 01-05-2004, 01:10 AM
C Style commenting - by oracle - 01-06-2004, 03:59 AM
C Style commenting - by Agamemnus - 01-06-2004, 08:39 PM
C Style commenting - by oracle - 01-07-2004, 03:33 AM
C Style commenting - by Agamemnus - 01-07-2004, 07:02 AM
C Style commenting - by oracle - 01-07-2004, 08:23 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)