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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:23:10+00:00 2026-06-05T09:23:10+00:00

I need to write a tool that can take a C code and put

  • 0

I need to write a tool that can take a C code and put pragmas on top of some functions. Which compiler framework is the easiest to do such a task. Also if you can provide an example, I would really appreciate it.

  • 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-05T09:23:13+00:00Added an answer on June 5, 2026 at 9:23 am

    If you want to do this reliably, you need a full C front end, and the ability to modify parsed code.

    Our DMS Software Reengineering Toolkit with its C Front End can probably do what you want. DMS can parse, build ASTs, and carry out custom transformations on source text, either procedural or as a surface syntax transform.

    There are some issues with macros and preprocessor directives; if you parse and retain these, it can do so in many cases but it expandis such directives where they are not “structured”. Retention means you don’t get a symbol table. If you expand all the directives, after parsing you can get a symbol table with the same content that a C compiler produces.

    For OP’s specific task, he’d like write a source to source transform something like the following:

     rule decorate_function_definition_with_pragma(fh:function_head, b: block): declaration -> declaration
           =  " \fh \b " ->
              " \fh 
                #pragma  my_pragma 
                \b "
             if some_condiiton(fh);
    

    where “my_pragma” is replace essentially by the pragma text he wants, and some_condition is custom predicate that filters matched function_headers for which the pragma should be inserted.

    The pattern matches against the syntax tree, so it cannot mismatch like sed or a regex might. The secret to this is that the pattern variables reference to grammar rules in the C Front End; a pattern variable of type function_head can only match those trees that the function_head grammar rule(s) can satisfy.

    One needs some trivial control logic to run this transformation just once for each encountered function definition.

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

Sidebar

Related Questions

I need to write a tool that exports some chats into offline HTML files.
I need to locate a command line tool that would allow me to write
We need to write a C/C++ code that will check whether the memory allocated
I need to write a small tool that parses a textual input and generates
I need to write a Red Hat Linux command line tool that launches a
I have a need for a personal command-line tool that should take the name
I need to write a java program which when executed pushes a command into
I need to write OpenGL ES 2-dimensional renderer on iOS. It should draw some
I need to write a program that reads from stdin and only writes non-empty
I need to write XML data to an encrypted file. I can read/write encrypted

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.