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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:34:53+00:00 2026-06-13T16:34:53+00:00

I am trying to write a rule for vera++ static analyzer. Since I did

  • 0

I am trying to write a rule for vera++ static analyzer. Since I did not found a group for vera++ here and that vera++ uses TCL to implement its rule for analysis I posted to TCL forum. I have worked on vera++ inspirel.com/vera/ce/doc/tclapi.html but since I do not know TCL much I wanted advices to approach further on.

Since I am a beginner in TCL programming but would like to know approach for a TCL program to list all local variables within a C++ source code file? I mean what approach and how it can achieved?

The issue I am facing is while parsing C++ source code files to detect local variable declaration?

  • 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-13T16:34:54+00:00Added an answer on June 13, 2026 at 4:34 pm

    It’s pretty complicated to parse for local (or any other) variable definitions using vera++ rules, but doable of course. The basic C++ parsing and tokenizing is done by vera++.

    The basic approach is to use vera++’s getTokens function in conjunction with a little state machine that checks for completed C++ statements. You need to gather tokens (and may be their values additionally, since you’ll need the variable names later to setup the list) and concatenate them until you have a complete statement. If you have a complete statement you can use a regular expression to check if it’s a variable defintion and extract the variable name from a submatch. Also you need to remember if you’re inside a {} block to know if it’s a local variable definition.

    You can find a sample for building a simple statemachine to gather the tokens to statements in vera++’s rule T019 that checks for complete curly braced blocks of code, to take as a starting point.

    I’ve done parsing for variable defintions with vera++ (to check for various naming conventions), but unfortunately can’t post the complete code since it’s proprietary work for my employer. But I can give you a snippet showing the regular expression I’m using to check for variable declarations:

    set isVar false
    if [regexp {\s+((extern\s+)?(static\s+|mutable\s+|register\s+|volatile\s+)?(const\s+)?)?((identifier#[^#]+#\s+colon_colon\s+)*identifier#[^#]+#)\s+(star\s+|const\s+|and\s+|less.*greater\s+|greater\s+)*(identifier#[^#]+#\s+colon_colon\s+)*identifier#([^#]+)#(\s+leftbracket.*rightbracket)?(\s+assign)?.*semicolon$} $statement m s1 s2 s3 s4 s5 s6 s7 s8 s9 s10] {
        set locVarname $s9
        set isVar true
        set currentMatch $m
    } elseif [regexp {\s+((extern\s+)?(static\s+|mutable\s+|register\s+|volatile\s+)?(const\s+)?)?(char\s+|int\s+|short\s+|long\s+|void\s+|bool\s+|double\s+|float\s+|unsigned\s+|and\s+|star\s+|unsigned\s+)+(identifier#[^#]+#\s+colon_colon)*\s+identifier#([^#]+)#(\s+leftbracket.*rightbracket)?(\s+assign)?.*semicolon$} $statement m s1 s2 s3 s4 s5 s6 s7 s8] {
        set locVarname $s7
        set isVar true
        set currentMatch $m
    }
    

    $statement contains the complete statement as mentioned before. Note that I’m concatenating the token value to the identifier token using identifier#<value># and use a regex group to extract it.

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

Sidebar

Related Questions

I'm trying to write a rule for my .htaccess file that checks for a
I'm trying to write a simple rule such that: /page gets implicitly routed to
I am trying to write an iptables rule that will redirect all outgoing UDP
I'm trying to write a function that will receive a CSS Rule to update
I'm trying to write a rule that redirects a request to a different file/path.
I am trying to write a Make rule that says, roughly, If you need
I'm trying to write a rewrite rule in my .htaccess file but not sure
I am trying to write a grammar for our custom rule engine which uses
I'm trying to write a custom FxCop code analysis rule that will warn developers
I'm trying to write to a file that is not in the directory that

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.