[OT] flex, yacc, and bison
I need to parse this format:
<Database ftpdatabase [hostname[:port]]>
[<DatabaseID somebody>]
[<DatabasePWD mypwd>]
[<Table ftp_users>
[<Uname uname>]
[<CryptedPwd cryptedpwd>]
[<FtpPath ftppath>]
</Table>]
</Database>
That's all that I currently have.
So, which of these would be the best tool (I know little about any of them).
If anyone gets the urge to just whip out a quick grammar file for me it
would be much appreciated.
Or at least point me to a beginner level tutorial somewhere.
advTHANKSance
DEJ
"Jackson, DeJuan" <djackson@cpsgroup.com> writes:
I need to parse this format:
<Database ftpdatabase [hostname[:port]]>
[<DatabaseID somebody>]
[<DatabasePWD mypwd>]
[<Table ftp_users>
[<Uname uname>]
[<CryptedPwd cryptedpwd>]
[<FtpPath ftppath>]
</Table>]
</Database>
That looks suspiciously like an SGML DTD to me...
Rather than doing the whole lex/yacc bit, I'd suggest finding some
ready-made SGML-parsing tools. For instance, if you are handy with
Perl I think there are some SGML modules in CPAN ... certainly there
are HTML parsers, which'd probably be easy to adapt to the purpose.
regards, tom lane
Import Notes
Reply to msg id not found: YourmessageofWed18Aug1999131147-0500D05EF808F2DFD211AE4A00105AA1B5D248541E@cpsmail | Resolved by subject fallback
Tom Lane <tgl@sss.pgh.pa.us> writes:
"Jackson, DeJuan" <djackson@cpsgroup.com> writes:
I need to parse this format:
<Database ftpdatabase [hostname[:port]]>
[<DatabaseID somebody>]
[<DatabasePWD mypwd>]
[<Table ftp_users>
[<Uname uname>]
[<CryptedPwd cryptedpwd>]
[<FtpPath ftppath>]
</Table>]
</Database>That looks suspiciously like an SGML DTD to me...
Well, it could almost kind of be SGML, but as specified, there's no
way it could possibly be XML (attributes have to have values, a couple
of other things), which is unfortunate, since that's where all the
cool tools are being developed these days.
Rather than doing the whole lex/yacc bit, I'd suggest finding some
ready-made SGML-parsing tools. For instance, if you are handy with
Perl I think there are some SGML modules in CPAN ... certainly there
are HTML parsers, which'd probably be easy to adapt to the purpose.
I agree with Tom that you try to find existing parsers tuned towards
this stuff, with the addition that you do your self a favor (if you
have the option to change the format), and change it to be something
that can be parsed as XML.
You don't mention what this is for, but if you're able to move to XML,
you can use Perl (which I personally prefer), Python, TCL, or even one
of several C libraries (expat or rxp or GNOME's libxml) that are
suprisingly easy to use, given that text hacking is not something that
is traditionally easy to do in C. The possibilities are much broader.
Mike.
Import Notes
Reply to msg id not found: TomLanesmessageofWed18Aug1999165935-0400
Tom Lane wrote:
"Jackson, DeJuan" <djackson@cpsgroup.com> writes:
I need to parse this format:
<Database ftpdatabase [hostname[:port]]>
[<DatabaseID somebody>]
[<DatabasePWD mypwd>]
[<Table ftp_users>
[<Uname uname>]
[<CryptedPwd cryptedpwd>]
[<FtpPath ftppath>]
</Table>]
</Database>That looks suspiciously like an SGML DTD to me...
Rather than doing the whole lex/yacc bit, I'd suggest finding some
ready-made SGML-parsing tools. For instance, if you are handy with
Perl I think there are some SGML modules in CPAN ... certainly there
are HTML parsers, which'd probably be easy to adapt to the purpose.
That's definitly not an SGML DTD and it isn't either valid SGML. It will
be hard to find a Perl Module.
-Egon
PS: a small and quick test if my email address is valid
I'm trying to write a ncftp_auth deamon that will utilize PostgreSQL. The
base SDK is in C. I'm adapting it to C++ because I feel like it, but Perl
would be a slightly steeper learning curve (sockets and all that). I'm
trying to get a conf file parser such that the login's can be in multiple
database and/or on different machines.
DEJ
Show quoted text
-----Original Message-----
From: Michael Alan Dorman [SMTP:mdorman-pgsql.hackers@debian.org]
Sent: Wednesday, August 18, 1999 4:46 PM
To: pgsql-hackers@postgreSQL.org
Subject: Re: [HACKERS] [OT] flex, yacc, and bisonTom Lane <tgl@sss.pgh.pa.us> writes:
"Jackson, DeJuan" <djackson@cpsgroup.com> writes:
I need to parse this format:
<Database ftpdatabase [hostname[:port]]>
[<DatabaseID somebody>]
[<DatabasePWD mypwd>]
[<Table ftp_users>
[<Uname uname>]
[<CryptedPwd cryptedpwd>]
[<FtpPath ftppath>]
</Table>]
</Database>That looks suspiciously like an SGML DTD to me...
Well, it could almost kind of be SGML, but as specified, there's no
way it could possibly be XML (attributes have to have values, a couple
of other things), which is unfortunate, since that's where all the
cool tools are being developed these days.Rather than doing the whole lex/yacc bit, I'd suggest finding some
ready-made SGML-parsing tools. For instance, if you are handy with
Perl I think there are some SGML modules in CPAN ... certainly there
are HTML parsers, which'd probably be easy to adapt to the purpose.I agree with Tom that you try to find existing parsers tuned towards
this stuff, with the addition that you do your self a favor (if you
have the option to change the format), and change it to be something
that can be parsed as XML.You don't mention what this is for, but if you're able to move to XML,
you can use Perl (which I personally prefer), Python, TCL, or even one
of several C libraries (expat or rxp or GNOME's libxml) that are
suprisingly easy to use, given that text hacking is not something that
is traditionally easy to do in C. The possibilities are much broader.Mike.
************
Check out "PostgreSQL Wearables" @ http://www.pgsql.com
Import Notes
Resolved by subject fallback
On 18-Aug-99 Jackson, DeJuan wrote:
I'm trying to write a ncftp_auth deamon that will utilize PostgreSQL. The
base SDK is in C. I'm adapting it to C++ because I feel like it, but Perl
would be a slightly steeper learning curve (sockets and all that). I'm
trying to get a conf file parser such that the login's can be in multiple
database and/or on different machines.
If you're into C/C++ (like I am), it's almost trivial to parse that into
individual strings. I was under the impression from your first note that
C/C++ wasn't an option. At the minimum, think strtok(). There's also
strsep() but it's not been one of my favorites. If you still need actual
code let me know and I can send you something.
Vince.
DEJ
-----Original Message-----
From: Michael Alan Dorman [SMTP:mdorman-pgsql.hackers@debian.org]
Sent: Wednesday, August 18, 1999 4:46 PM
To: pgsql-hackers@postgreSQL.org
Subject: Re: [HACKERS] [OT] flex, yacc, and bisonTom Lane <tgl@sss.pgh.pa.us> writes:
"Jackson, DeJuan" <djackson@cpsgroup.com> writes:
I need to parse this format:
<Database ftpdatabase [hostname[:port]]>
[<DatabaseID somebody>]
[<DatabasePWD mypwd>]
[<Table ftp_users>
[<Uname uname>]
[<CryptedPwd cryptedpwd>]
[<FtpPath ftppath>]
</Table>]
</Database>That looks suspiciously like an SGML DTD to me...
Well, it could almost kind of be SGML, but as specified, there's no
way it could possibly be XML (attributes have to have values, a couple
of other things), which is unfortunate, since that's where all the
cool tools are being developed these days.Rather than doing the whole lex/yacc bit, I'd suggest finding some
ready-made SGML-parsing tools. For instance, if you are handy with
Perl I think there are some SGML modules in CPAN ... certainly there
are HTML parsers, which'd probably be easy to adapt to the purpose.I agree with Tom that you try to find existing parsers tuned towards
this stuff, with the addition that you do your self a favor (if you
have the option to change the format), and change it to be something
that can be parsed as XML.You don't mention what this is for, but if you're able to move to XML,
you can use Perl (which I personally prefer), Python, TCL, or even one
of several C libraries (expat or rxp or GNOME's libxml) that are
suprisingly easy to use, given that text hacking is not something that
is traditionally easy to do in C. The possibilities are much broader.Mike.
************
Check out "PostgreSQL Wearables" @ http://www.pgsql.com************
Check out "PostgreSQL Wearables" @ http://www.pgsql.com
--
==========================================================================
Vince Vielhaber -- KA8CSH email: vev@michvhf.com flame-mail: /dev/null
# include <std/disclaimers.h> TEAM-OS2
Online Campground Directory http://www.camping-usa.com
Online Giftshop Superstore http://www.cloudninegifts.com
==========================================================================
On 18-Aug-99 Vince Vielhaber wrote:
On 18-Aug-99 Jackson, DeJuan wrote:
I'm trying to write a ncftp_auth deamon that will utilize PostgreSQL. The
base SDK is in C. I'm adapting it to C++ because I feel like it, but Perl
would be a slightly steeper learning curve (sockets and all that). I'm
trying to get a conf file parser such that the login's can be in multiple
database and/or on different machines.If you're into C/C++ (like I am), it's almost trivial to parse that into
individual strings. I was under the impression from your first note that
C/C++ wasn't an option. At the minimum, think strtok(). There's also
strsep() but it's not been one of my favorites. If you still need actual
code let me know and I can send you something.
It's my bestst:
int split(char delem, char *str, ... )
{
char *tmp, *_src, *t, **s;
int fields = 0;
_src = str;
va_list ap;
va_start(ap, str);
if (! (tmp=new char[2048]) )
return -1;
while(_src)
{ t = _src;
while (*t && ((*t) != delem) ) ++t;
s = va_arg(ap, char **);
if (!s || !*t)
break;
*s = ( t-_src-1 > 0) ? strndup(_src,t-_src-1) : 0 ;
_src = t+1;
++ fields;
}
return fields;
}
---
Dmitry Samersoff, dms@wplus.net, ICQ:3161705
http://devnull.wplus.net
* There will come soft rains ...
Thanks guys, for all the help.
The reason that I was thinking 'grammar parser' was that the spec of this
format may change. I was looking for something that would be quick, but
easily extended as the grammar changed/evolved. Also my next project will
need the same functionality if not an extension of the same grammar.
Again thanks,
-DEJ
Show quoted text
-----Original Message-----
On 18-Aug-99 Vince Vielhaber wrote:
On 18-Aug-99 Jackson, DeJuan wrote:
I'm trying to write a ncftp_auth deamon that will utilize PostgreSQL.
The
base SDK is in C. I'm adapting it to C++ because I feel like it, but
Perl
would be a slightly steeper learning curve (sockets and all that). I'm
trying to get a conf file parser such that the login's can be inmultiple
database and/or on different machines.
If you're into C/C++ (like I am), it's almost trivial to parse that into
individual strings. I was under the impression from your first notethat
C/C++ wasn't an option. At the minimum, think strtok(). There's also
strsep() but it's not been one of my favorites. If you still needactual
code let me know and I can send you something.
It's my bestst:
int split(char delem, char *str, ... )
{
char *tmp, *_src, *t, **s;
int fields = 0;_src = str;
va_list ap;
va_start(ap, str);if (! (tmp=new char[2048]) )
return -1;while(_src)
{ t = _src;
while (*t && ((*t) != delem) ) ++t;
s = va_arg(ap, char **);
if (!s || !*t)
break;
*s = ( t-_src-1 > 0) ? strndup(_src,t-_src-1) : 0 ;
_src = t+1;
++ fields;
}return fields;
}---
Dmitry Samersoff, dms@wplus.net, ICQ:3161705
http://devnull.wplus.net
* There will come soft rains ...
Import Notes
Resolved by subject fallback