Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5968633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:07:04+00:00 2026-05-22T20:07:04+00:00

I’m trying to parse Bibtex files using lex/yacc. Strings in the bibtex database can

  • 0

I’m trying to parse Bibtex files using lex/yacc. Strings in the bibtex database can be surrounded by quotes “…” or with braces – {…}

But every entry is also enclosed in braces. How do differentiate between an entry and a string surrounded by braces?

@Book{sweig42,
  Author =   { Stefan Sweig },
  title =    { The impossible book },
  publisher =    { Dead Poet Society},
  year =     1942,
  month =        mar
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:07:05+00:00Added an answer on May 22, 2026 at 8:07 pm

    you have various options:

    • lexer start conditions (from a Lex tutorial)

      building on the ideas from greg ward, enhance your lex rules with start conditions (‘modes’ as they are called in the referenced source).

    specifically, you would have the start conditions BASIC ENTRY STRING and the following rules (example taken and slightly enhanced from here):

    %START BASIC ENTRY STRING
    %%
    
    /* Lexical grammar, mode 1: top-level */
    <BASIC>AT           @ { BEGIN ENTRY; }
    <BASIC>NEWLINE      \n
    <BASIC>COMMENT      \%[^\n]*\n
    <BASIC>WHITESPACE.  [\ \r\t]+
    <BASIC>JUNK         [^@\n\ \r\t]+
    
    /* Lexical grammar, mode 2: in-entry */
    <ENTRY>NEWLINE      \n
    <ENTRY>COMMENT      \%[^\n]*\n
    <ENTRY>WHITESPACE   [\ \r\t]+
    <ENTRY>NUMBER       [0-9]+
    <ENTRY>NAME         [a-z0-9\!\$\&\*\+\-\.\/\:\;\<\>\?\[\]\^\_\`\|]+ { if (stricmp(yytext, "comment")==0) { BEGIN STRING; } }
    <ENTRY>LBRACE       \{ { if (delim == '\0') { delim='}'; } else { blevel=1; BEGIN STRING; } }
    <ENTRY>RBRACE       \} { BEGIN BASIC; }
    <ENTRY>LPAREN       \( { BEGIN STRING; delim=')'; plevel=1; }
    <ENTRY>RPAREN       \)
    <ENTRY>EQUALS       =
    <ENTRY>HASH         \#
    <ENTRY>COMMA        ,
    <ENTRY>QUOTE        \" { BEGIN STRING; bleveL=0; plevel=0; }
    
    /* Lexical grammar, mode 3: strings */
    <STRING>LBRACE       \{ { if (blevel>0) {blevel++;} }
    <STRING>RBRACE       \} { if (blevel>0) { blevel--; if (blevel == 0) { BEGIN ENTRY; } } }
    <STRING>LPAREN       \( { if (plevel>0) { plevel++;} }
    <STRING>RPAREN       \} { if (plevel>0) { plevel--; if (plevel == 0) { BEGIN ENTRY; } } }
    <STRING>QUOTE        \" { BEGIN ENTRY; }
    

    please note that the rule set is by no means complete but should get you started. more details to be found here.

    • btparse

      These docs explain in a fairly detailed fashion thenintricacies of parsing the bibtex formats and comes with a ‘python parser.

    • biblex

      you might also be interested in employing the unix toolchain of biblex and bibparse. these tools generate and parse a bibtex token stream, respectively.

      more info can be found here.

    best regards, carsten

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.