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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:16:29+00:00 2026-06-11T17:16:29+00:00

I am using Lex and Yacc to design a parser and encounter some issue

  • 0

I am using Lex and Yacc to design a parser and encounter some issue about comment.

I use the following Lex rule.

'#'[^('\r'|'\n')]*    { /* do nothing */ }

It works, but at the end of execution all the comments are printed to the standard output. Is there way to clear that? Thank you for the suggestion.

  • 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-11T17:16:31+00:00Added an answer on June 11, 2026 at 5:16 pm

    The characters ', |, (, and ) have no special meaning in [], so you’re only matching (and discarding) comments that don’t contain them. In addition, in most versions of lex ' has no special meaning at all — only " can be used to quote literal strings. What you probably want is:

    "#"[^\r\n]*     { /* do nothing */ }
    

    In addition, # has no special meaning either, so there’s no real need to quote it.

    In general, if you’re using lex (or flex) as the input to a parser, you NEVER want the default echoing behavior, so its best to add a ‘catch-all’ rule at the very end:

    .|\n            { fprintf(stderr, "Unexpected character '%c' in input\n", *yytext); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some advice about writing a parser (using C and Lex) that accepts
hi there i'm trying to make a simple parser and using lex and yacc.
I was trying learn lex and yacc using the oreilly book. I tried following
i want to create a php parser.i was thinking of using lex/yacc for the
I am developing a simple translator from MathML to Latex, using Lex and Yacc.
How much time would it take to write a C++ compiler using lex/yacc? Where
I'd like to use lex/yacc to read in a delimited text file. This would
I've been using lex/yacc and now I'm trying to switch to ANTLR. The major
I'm trying to parse Bibtex files using lex/yacc. Strings in the bibtex database can
I'm trying to write a shell using yacc and lex and I'm running into

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.