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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:31:18+00:00 2026-05-11T05:31:18+00:00

I’d like to parse simple C++ typedef instructions such as typedef Class NewNameForClass; typedef

  • 0

I’d like to parse simple C++ typedef instructions such as

typedef Class NewNameForClass; typedef Class::InsideTypedef NewNameForTypedef; typedef TemplateClass<Arg1,Arg2> AliasForObject; 

I have written the corresponding grammar that i’d like to see used in parsing.

Name <- ('_'|letter)('_'|letter|digit)* Type <- Name Type <- Type::Name Type <- Name Templates Templates <- '<' Type (',' Type)* '>' Instruction <- 'typedef' Type Name ';' 

Once this is parsed, all i’ll want to do is to generate xml with the same information (but layed out differently)

What is the most effective language for writing such a program ? How can you achieve this ?

EDIT : What i have come up with using Boost Spirit (it’s not perfect, but it’s good enough for me, at least for now)

   rule<> sep_p = space_p;    rule<> name_p =  (ch_p('_')|alpha_p) >> *(ch_p('_')|alpha_p|digit_p);    rule<> type_p = name_p            >> !(*sep_p >>str_p('::') >> *sep_p>> name_p)            >>  *(*sep_p >> ch_p('*') )            >> !(*sep_p >> str_p('const'))            >> !(*sep_p >> ch_p('&'));    rule<> templated_type_p = name_p >> *sep_p            >> ch_p('<') >> *sep_p            >> (*sep_p>>type_p>>*sep_p)%ch_p(',')            >> ch_p('>') >> *sep_p;     rule<> typedef_p = *sep_p                    >> str_p ('typedef')                    >> +sep_p >> (type_p|templated_type_p)                    >> +sep_p >> name_p                    >> *sep_p >> ch_p(';')  >> *sep_p;    rule<> typedef_list_p = *typedef_p; 
  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T05:31:18+00:00Added an answer on May 11, 2026 at 5:31 am

    I would alter the grammar slightly

    ShortName <- ('_'|letter)('_'|letter|digit)* Name <- ShortName Name <- Name::ShortName Type <- Name Type <- Name Templates Templates <- '<' Type (',' Type)* '>' Instruction <- 'typedef' Type Name ';' 

    Also your grammar leaves out the following cases

    1. Multiple typedef targets.
    2. Pointer targets
    3. Function pointers (this is by far the most difficult)

    Parsing a grammar (i love the irony) is a fairly straight forward operation. If you wanted to actually use the grammar in a functional way, I would say the best bet is a lex/yacc combination.

    But from your question it appears that you want to spit it out to another format. There really isn’t a language designed for this so I would say use whatever language you’re most comfortable with.

    Edit

    The OP asked about multiple typedef targets. It’s perfectly legally for a typedef declaration to have more than 1 target. For Example:

    typedef _SomeStruct SomeStruct, *PSomeStruct 

    This creates 2 typedef names.

    1. SomeStruct which is equivalent to ‘struct _SomeStruct’
    2. PSomeStruct which is equivalent to ‘struct _SomeStruct*’
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 145k
  • Answers 145k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I suspect you're seeing default padding/margins from you h4 tag.… May 12, 2026 at 8:55 am
  • Editorial Team
    Editorial Team added an answer You can draw pretty braces using sigmoidals. I don't have… May 12, 2026 at 8:55 am
  • Editorial Team
    Editorial Team added an answer This issue has to do with the CSS spec on… May 12, 2026 at 8:55 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.