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

  • SEARCH
  • Home
  • 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 8224463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:04:49+00:00 2026-06-07T15:04:49+00:00

I’m trying to write a parser using flex and bison but I’m confused on

  • 0

I’m trying to write a parser using flex and bison but I’m confused on how it works. I’m trying to take a text file formatted in the following way:

Version Header Version 1.00 <--- File always starts with a header
Key                     : Value <--- Each section includes these but these after the version header are in the "Root" section
==Section Name <--- A section
$Key                    : Value <--- These are properties
Key                     : Value <--- Same thing as in the "Root" section

Sample Format:

NasuTek Licensing Version 1.00
Vendor                  : NASUTEKENTERPRISES
Notice                  : NasuTek Enterprises
License Group           : NasuTek Asheila
License Name            : NasuTek Asheila
Vendor Notice           : NasuTek Asheila Internal Build License
Serial                  : ASHEL-87267-4987-3737-37821:32742
Start Date              : Wed July 04 00:00:00 2012
End Date                : Sat July 20 00:00:00 2013
Trial                   : Yes
Count                   : 0
Components              : EXPORT
Host                    : Any

==Software Configuration
$Signed Section         : Yes
Export Configuration    : {
    Supports Export to XML        : Yes
    Supports Export to Text       : Yes
}

==Signature
vpUsQJ+Qo4OS+RQg0vuLW0mXjAj/o6v[trunicated]

How can I accomplish this as I’m confused on grouping. I can get it to see the key pairs as thats simple enough, but i dont know how to deal with the splitting using == and the {} pairs?

  • 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-06-07T15:04:52+00:00Added an answer on June 7, 2026 at 3:04 pm

    Okay, your grammar isn’t all that simple. But, what I had done was define a token in the lexer to treat \n== as the section start symbol (which I called EQEQ). So, the grammar rule looked like:

    section_line:
          EQEQ section_name NEWLINE
        ;
    

    And the tokenizing rule looked like:

    "\n=="           { BEGIN(SEC); return EQEQ; }
    

    I used a start condition in order to be able to treat the word Signature like a keyword if it was right after the EQEQ, and another start condition so that a signature section would just pull in the signature data as a single text blob:

    <SEC>"Signature" { BEGIN(SIG); return SIGNATURE; }
    <SIG>{text}      { return (BEGIN(INITIAL), TEXT); }
    

    The grouping rule is easiest defined in a single rule. This is the grammar I used for a property key-value pair:

    section_property:
          key COLON value NEWLINE
        | key COLON value_block NEWLINE
        ;
    

    And then this is the rule I used to define a value_block:

    value_block:
          LBRACE NEWLINE sub_properties RBRACE
        ;
    

    And, a sub_property looks just like a section_property.

    Whenever a new section is encountered, your parsing code should remember which section the subsequent value pairs belong to. Likewise, when parsing a sub-property block, the enclosing property key should be saved so that the sub-properties can be appropriately assigned.

    One thing that could trip you up in yacc like parsers is its bottom up nature. As the leaf elements of a rule are recognized, save the values in the leaf rules, and in your enclosing rule, refer to the saved values. For example, this rule:

    words:
          WORD { words_add($1); free($1); }
        | WORD { words_add($1); free($1); } words
        ;
    

    saves consecutive words into a save buffer representing the word sequence. Then, in an enclosing rule, that save buffer is saved again:

    key:
          words { words_save_as_key(); }
        ;
    

    Where words_save_as_key basically dups the saved words buffer, and then resets that buffer for a different sequence that will be saved (likely, the sequence representing the associated value).

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

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
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
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.