Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > C parser document

Reply
Thread Tools

C parser document

 
 
Chris Dollin
Guest
Posts: n/a
 
      09-02-2005
Jonas Geiregat wrote:

> I'm trying to parse a configuration file,
> this is the first time I'm trying something like this, and it seems hard.
> C's I/O functions are a mess and hard to use , that is if you want to
> write code in a good way.


I've written parsers for one style of config file in C; the I/O
functions were pretty much a non-issue.

Be more specific about what you're trying to parse and the problems
you've had.

--
Chris "electric hedgehog" Dollin
Almost all predictions about life in 2015 are wrong in some fundamental
respect.
 
Reply With Quote
 
 
 
 
ajm
Guest
Posts: n/a
 
      09-02-2005
I hardly think the I/O functions "are a mess" (not at all sure though
what you mean by that but guess you still have a bit of reading
ahead of you...ho hum so give the following a try:

http://www.gnu.org/software/libc/manual/html_node/

for a start (I/O Overview and I/O Streams are what you might be looking
for and the rest probably doesn't hurt), then of course there are the
manpages etc. etc.

if you ever get around to a specific question you might want to post
that too

hth,
ajm.

 
Reply With Quote
 
 
 
 
Jonas Geiregat
Guest
Posts: n/a
 
      09-02-2005
I'm trying to parse a configuration file,
this is the first time I'm trying something like this, and it seems hard.
C's I/O functions are a mess and hard to use , that is if you want to
write code in a good way.
I've tried google many times looking for some good document article that
talks about C I/O and parsing files, most of the docs that I came across
just talk about basic I/O things I can also learn from reading my man pages.

Any kind of advise is welcome!
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      09-02-2005
Jonas Geiregat wrote:

> I'm trying to parse a configuration file,
> this is the first time I'm trying something like this, and it seems
> hard. C's I/O functions are a mess and hard to use , that is if you
> want to write code in a good way. I've tried google many times
> looking for some good document article that talks about C I/O and
> parsing files, most of the docs that I came across just talk about
> basic I/O things I can also learn from reading my man pages.
>
> Any kind of advise is welcome!


Here's my advice. This is probably one of the worst posts I've seen to
this group. You don't describe what you are trying to do. You don't say
what problems you have. You gratuitously insult the programming
language you are trying to get help in.

Please read the following. It is not from our FAQ list, rather from
comp.lang.c++, but I cribbed it anyway:

Post compileable code: avoid ellipses, such as void f() { ... }

Post complete code: put in all necessary #includes and declarations of
needed types and functions

Post minimal code: just enough to demonstrate the problem

Post one compilation unit: if possible, combine Foo.h into Foo.c

Post the exact messages you received; differentiate between compiler,
linker, and runtime messages

Make sure main() has a return type of int, not void!



Brian
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-02-2005
"Default User" <(E-Mail Removed)> writes:
> Jonas Geiregat wrote:
>
>> I'm trying to parse a configuration file,
>> this is the first time I'm trying something like this, and it seems
>> hard. C's I/O functions are a mess and hard to use , that is if you
>> want to write code in a good way. I've tried google many times
>> looking for some good document article that talks about C I/O and
>> parsing files, most of the docs that I came across just talk about
>> basic I/O things I can also learn from reading my man pages.
>>
>> Any kind of advise is welcome!

>
> Here's my advice. This is probably one of the worst posts I've seen to
> this group. You don't describe what you are trying to do. You don't say
> what problems you have. You gratuitously insult the programming
> language you are trying to get help in.


I've seen *much* worse posts than that.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      09-02-2005
Keith Thompson wrote:

> "Default User" <(E-Mail Removed)> writes:


> > Here's my advice. This is probably one of the worst posts I've seen
> > to this group. You don't describe what you are trying to do. You
> > don't say what problems you have. You gratuitously insult the
> > programming language you are trying to get help in.

>
> I've seen much worse posts than that.


Worseness is in the eye of the beholder.



Brian
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-02-2005
"Default User" <(E-Mail Removed)> writes:
> Keith Thompson wrote:
>> "Default User" <(E-Mail Removed)> writes:
>> > Here's my advice. This is probably one of the worst posts I've seen
>> > to this group. You don't describe what you are trying to do. You
>> > don't say what problems you have. You gratuitously insult the
>> > programming language you are trying to get help in.

>>
>> I've seen much worse posts than that.

>
> Worseness is in the eye of the beholder.


Sure, but things like that tend to reinforce comp.lang.c's
(undeserved, IMHO) reputation as a bunch of overly picky topicality
police.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      09-03-2005
Default User wrote:
> Jonas Geiregat wrote:
>
>
>>I'm trying to parse a configuration file,
>>this is the first time I'm trying something like this, and it seems
>>hard. C's I/O functions are a mess and hard to use , that is if you
>>want to write code in a good way. I've tried google many times
>>looking for some good document article that talks about C I/O and
>>parsing files, most of the docs that I came across just talk about
>>basic I/O things I can also learn from reading my man pages.
>>
>>Any kind of advise is welcome!

>
>
> Here's my advice. This is probably one of the worst posts I've seen to
> this group. [...]


For your information, it is considered polite to lurk
on a newsgroup for a few weeks before starting to post. If
you have seen nothing worse than the O.P., you cannot have
been here more than a few seconds. Patience, Grasshopper.

--
Eric Sosman
(E-Mail Removed)lid
 
Reply With Quote
 
John Bode
Guest
Posts: n/a
 
      09-03-2005

Jonas Geiregat wrote:
> I'm trying to parse a configuration file,
> this is the first time I'm trying something like this, and it seems hard.
> C's I/O functions are a mess and hard to use , that is if you want to
> write code in a good way.
> I've tried google many times looking for some good document article that
> talks about C I/O and parsing files, most of the docs that I came across
> just talk about basic I/O things I can also learn from reading my man pages.
>
> Any kind of advise is welcome!


It would help a bit if you could tell us what kind of problems you're
running into; what's the structure of the file you're trying to parse,
for example?

Advice on C I/O routines:

1. Avoid gets() like the plague. Better yet, just pretend gets()
never existed. Using it *will* introduce a point of failure in your
code.

2. Unless your input is relatively simple in structure and *always*
well-formed, don't use scanf() to read and assign items directly from
the stream; scanf() doesn't give you the ability to easily recognize or
recover from malformed input.

3. Use fgets() to read in lines of input, and then process the
resulting buffer with strtok(), strstr(), strchr(), sscanf(), or some
combination of the above. Alternately, use fgetc() to read in a single
character at a time and process via state tables, but unless you're
writing a compiler front-end or something similar, that's probably
overkill. And if you *are* writing a compiler front-end, use lex and
yacc or something similar instead of rolling your own.

4. Break your parsing code into several layers of abstraction, with
the C I/O routines wrapped in more abstract operations like
GetNextLine() or GetNextToken(), which are in turn called by
progressively more abstract operations like GetLogfileName() or
GetStartupParams(). This makes code a bit easier to write; you're only
focusing on as much complexity as you need to at any particular level.
It also allows you to make changes at the native input level without
hacking the application logic.

5. Before starting *any* of this, make sure there isn't a tool already
out there to do what you're doing. For example, if your input is in
XML format, there are already a number of parser libraries available
for parsing XML documents. And there are tools like the previously
mentioned lex and yacc (flex and bison in the GNU world) that allow you
to build robust and sophisticated parsers.

6. Of course, make sure you're using the right tool for the job in the
first place. The old joke goes something like "when confronted with a
problem, a programmer says, 'I know, I'll use XML.' The programmer now
has two problems. " XML's wonderful, but do you *really* need to link
in a heavyweight DOM parser to handle 5 lines of text? Do you really
need to go through the hassle of generating code from lex and yacc if
all you're dealing with is a comma-delimited list of name-value pairs?
This is why it's important for you to give us some idea of what you're
trying to do.

 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      09-04-2005

Eric Sosman wrote:
> Default User wrote:


> > Here's my advice. This is probably one of the worst posts I've seen to
> > this group. [...]

>
> For your information, it is considered polite to lurk
> on a newsgroup for a few weeks before starting to post. If
> you have seen nothing worse than the O.P., you cannot have
> been here more than a few seconds.


Ha ha.

Believe me, I'm sincere. I rate this worse than troll posts or even
ERT's bad advice posts, because this person's post so utterly fails to
accomplish anything useful for him.



Brian

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
import parser does not import parser.py in same dir on win Joel Hedlund Python 2 11-11-2006 03:46 PM
import parser does not import parser.py in same dir on win Joel Hedlund Python 0 11-11-2006 11:34 AM
XML Parser VS HTML Parser ZOCOR Java 11 10-05-2004 01:58 PM
XMLparser: Difference between parser.setErrorHandler() vs. parser.setContentHandler() Bernd Oninger Java 0 06-09-2004 01:26 AM
XMLparser: Difference between parser.setErrorHandler() vs. parser.setContentHandler() Bernd Oninger XML 0 06-09-2004 01:26 AM



Advertisments