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 7589855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:15:55+00:00 2026-05-30T20:15:55+00:00

I have a parser generated using Flex/Bison – it parses each line of a

  • 0

I have a parser generated using Flex/Bison – it parses each line of a file and returns some output for that line. My input data is a little corrupt, and what I’d like to do is add a special character (like a #) to the beginning of lines that I’d like bison to ignore, and merely echo the line to the output.

So if my input looked like

apples 3 ate
oranges 4 consumed
# rhino ten

my output after parsing the lines might be

I ate three apples
I consumed four oranges
# rhino ten

Is there some easy way to do this ?

  • 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-30T20:15:56+00:00Added an answer on May 30, 2026 at 8:15 pm

    You can do this lexically in the flex scanner.

    Something like:

    ^#.*\n   { fputs(yytext, stdout); /* increment line number */ }
    

    Or in the parser:

    ^#.*\n   { yystype.lexeme = strdup(yytext);
               return HASH_ECHO; /* token type defined in parser */ }
    

    In the parser just generate from your top level grammar a production for this:

    /* in top section */
    %union {
       /* ... */
       char *lexeme;
       /* ... */
    }
    
    %token<lexeme> HASH_ECHO
    /*...*/
    
    /* make sure this rule is hooked into your grammar, of course */
    hash_echo : HASH_ECHO { fputs($1, stdout); free($1); }
              ;
    

    Not sure about including that newline; I have no idea how you’re handling those. So it may not be appropriate.

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

Sidebar

Related Questions

I have some C code that parses a file and generates another file of
i have a console application that generated from bison (a parser) and i want
By default, a parser generated using ANTLR-3 extends from org.antlr.runtime.Parser. How do I have
To outline: I have a parser that grabs Cell references using the following regex
I have a tree parser that's doing semantic analysis on the AST generated by
I have a .NET web-service client that has been autogenerated from a wsdl-file using
I have lexer/parser (Generated from an ANTLR grammar file) which (for performance reasons) I
i am using flex as lexical analyzer and bison as parser generator , but
I'm using Bison and Flex to make a reentrant scanner/parser pair but can't wrap
I have a user model that is generated using Devise. I am extending this

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.