Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion parsing a bibtex file

Received: by 10.180.95.2 with SMTP id dg2mr995606wib.2.1348440640394;
        Sun, 23 Sep 2012 15:50:40 -0700 (PDT)
Path: ed8ni35206690wib.0!nntp.google.com!fu-berlin.de!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From: =?UTF-8?Q?=E0=A6=B0=E0=A7=81=E0=A6=A6=E0=A7=8D=E0=A6=B0_?=
	=?UTF-8?Q?=E0=A6=AC=E0=A7=8D=E0=A6=AF=E0=A6=BE=E0=A6=A3=E0=A6=BE?=
	=?UTF-8?Q?=E0=A6=B0=E0=A7=8D=E0=A6=9C=E0=A7=80?=
	 <bnrj.ru...@gmail.com>
Newsgroups: comp.unix.programmer
Subject: Re: parsing a bibtex file
Date: Sun, 23 Sep 2012 23:50:30 +0100
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <1348440630.1735.13.camel@roddur>
References: <1348351577.3333.14.camel@roddur>
	 <k3mebt$6of$1@news.albasani.net>
	 <dee27232-7de1-4c8d-b74e-9f88d74e8e5d@googlegroups.com>
	 <0.b8221c627d142cb7dfc8.20120923231014BST.87obkw2xx5.fsf@bsb.me.uk>
Mime-Version: 1.0
Injection-Info: mx04.eternal-september.org; posting-host="d6ebe36a02610b7141cb3b93e5aa93c2";
	logging-data="20364"; mail-complaints-to="ab...@eternal-september.org";	posting-account="U2FsdGVkX18S+xLxb07kKIPS0H2dPA3I"
In-Reply-To: <0.b8221c627d142cb7dfc8.20120923231014BST.87obkw2xx5.fsf@bsb.me.uk>
X-Mailer: Evolution 3.4.4 (3.4.4-1.fc17)
Cancel-Lock: sha1:BuYYCj5F/B/bUnvID2EUDX96e90=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Ben,=20
Thanks for your reply.
I am trying to learn parsing (and may be scrapping some time later),
which means, I should not use ready-to-use solution(its self assigned
work, please don't assume I am asking you to solve my homework).
As in the first post in this thread, I stated that, I need to store
value of each author token.
So, if in my bibtex file has entries like:
@article{mrx05,=20
Author =3D "Mr. X",=20
Title =3D {Something Great},=20
Publisher =3D "nob" # "ody"},=20
Year =3D 2005,=20
}=20
@article{mra12,=20
Author =3D "Mr. A and Mr. B",=20
Title =3D {Something Equally Great},=20
Publisher =3D "nob" # "ody"},=20
Year =3D 2012,=20
}=20

I would like to have
array_author[0]=3D"Mr. X"
array_author[1]=3D"Mr. A and Mr. B"

array_year[0]=3D2005
array_year[1]=3D2012

and so on.
For completeness, I am pasting the flex code that I have managed(copy
from the first post). It parses everything correctly, but I don't know
how to store the results in array. Please help.

$ cat pbib.l=20
%{
#include <stdio.h>
#include <stdlib.h>
%}

%{
char yylval;
int YEAR;
%}
%x author
%x title
%x pub
%x year
%%
@[a-zA-Z][a-zA-Z0-9]*   { printf("%s",yytext);}
[Aa]uthor=3D                 {BEGIN(author);}
<author>\"[a-zA-Z\/.]+\"  { printf("%s",yytext);
                           BEGIN(INITIAL);}
[Yy]ear=3D                   {BEGIN(year);}
<year>\"[0-9]+\"        {printf("%s",yytext);
                        BEGIN(INITIAL);}
[Tt]itle=3D                 {BEGIN(title);}
<title>\"[a-zA-Z\/.]+\"  { printf("%s",yytext);
                           BEGIN(INITIAL);}
[Pp]ublisher=3D                 {BEGIN(pub);}
<pub>\"[a-zA-Z\/.]+\"  { printf("%s",yytext);
                           BEGIN(INITIAL);}
[a-zA-Z0-9\/.-]+=3D        printf("ENTRY TYPE ");
\"                      printf("QUOTE ");
\{                      printf(" ");
\}                      printf(" ");
;                       printf("SEMICOLON ");
\n                      printf("\n");
[\,\n\}][\,\}]          printf("\nNEWENTRY");
%%