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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:32:35+00:00 2026-06-02T07:32:35+00:00

I have been looking at flex and bison tutorials online trying to solve my

  • 0

I have been looking at flex and bison tutorials online trying to solve my problem by they all use very simple examples and mine is more complicated. I need to parse a file which may contain input which looks like this:

f(x,g(x))

These functions may also have an arbitrary number of arguments.

The problem is that I need both f and g to be treated as functions by the parser and not have f as a function and g as a parameter of x. in other words I need output that looks like this:

[f,x,[g,x]]

and not like:

[f, x, g(x)]

Could someone tell me how to best do this and possibly provide the regex (since I’m not that good with them)?

  • 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-02T07:32:36+00:00Added an answer on June 2, 2026 at 7:32 am

    At the lexical (flex) level, you would recognize four tokens as identifiers: f, x, g, and x. At the syntax (bison) level, you would recognize g(x) and f(x, g(x)) as expressions. Very schematically:

    expression -> numeric-literal | 
                  identifier |
                  identifier left-parenthesis arguments right-parenthesis
    
    arguments -> argument | 
                 argument comma arguments
    
    argument -> expression
    

    This little example will just give you the flavor of the difference between recognizing tokens and parsing.

    You could also parse arguments as:

    arguments -> argument | 
                 arguments comma argument
    

    There are some subtle differences between the two, which might or might not be relevant to your problem.

    The regular expression to recognize an identifier at the lexical level is whatever you like. Perhaps

    [a-zA-Z][a-zA-Z0-9]*
    

    in other words, a letter followed by optional digits and letters.

    A good book to start with would be John Levine’s lex & yacc. I have not used his flex & bison, but I would recommend it on the strength of the earlier book.

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

Sidebar

Related Questions

Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been looking all over for how to compare char elements in a
I have been looking for a solution to this problem for a while now
I have been looking into different types of timers that i could use for
I have been looking at how I could use Single linked lists using the
I have been looking all over MSDN and can't find a reason why Thread
I have been looking at authorize.net, notably their CIM and DPM solutions. The problem
I have been looking into IKVMing Apache's FOP project to use with our .NET
I have been looking around for solutions, and tried to implement what is often
I have been looking into CruiseControl configuration recently (I'm a complete CC noob) and

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.