To get a trial key
fill out the form below
Team License (a basic version)
Enterprise License (an extended version)
* By clicking this button you agree to our Privacy Policy statement

Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

Free PVS-Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
Description of VivaVisualCode

Description of VivaVisualCode

Jul 02 2008

This article concerns the program VivaVisualCode, showing how to use VivaCore library. VivaVisualCode represents in a graphic form the parse tree of the input source code in C++.

Introduction

Many libraries have a great disadvantage of absence of examples allowing you to consider the results of their work in a simple visual form. It is usual in the sphere of analysis and processing of programs' source code. Demo examples are made as programs accepting through the command line files' names, a lot of keys and generating other files at output. This user-unfriendly interface causes negative attitude to the library while using it for the first time, no matter whether the library is suitable for the task being solved.

We tried to use an approach that would allow the user to understand what he deals with as quickly as possible. Developing a program demonstrating the abilities of VivaCore library we decided to make it as a graphic application building a parse tree on the input C++ code. As the result a demo program VivaVisualCode appeared which you may download. You may download both source texts (Visual Studio 2005 project) and the executable module.

What is VivaCore

VivaCore is an open library for working with C and C++ code. The library is intended for implementing on its basis systems of code refactoring, static and dynamic analysis, code transformation or optimization systems, language extensions, subsystems of syntax highlighting, systems of building documentation on the code and other similar tools.

As a starting point for creation of VivaCore library another open library OpenC++ was taken: http://opencxx.sourceforge.net

To learn more about VivaCore library you may read the article "The essence of the code analysis library VivaCore" here: https://pvs-studio.com/en/blog/posts/a0013/

License on VivaCore library allows you to use, copy and distribute it both in binary form and as source code both for commercial and non-commercial use without any payments to the authors of the library. You are only to mention the authors of the source libraries (OpenC++ and VivaCore).

You may download VivaCore library.

What is VivaVisualCore?

VivaVisualCode is a program demonstrating in a visual form the abilities of VivaCode library in building of parse trees for C++ code. VivaVisualCode implements graphic representation of a parse tree on the screen (see figure 1).

a0025_VivaVisualCode/image1.png

Figure 1. An example of a parse tree for code "float Value = 10.0 * 20.0;" built by VivaVisualCode.

The Parse Tree being created differs from the Abstract Syntax Tree (AST) in that it contains nodes for those syntax rules which don't influence the program's semantics. A typical example of such nodes is grouping parentheses while grouping of operands in AST is defined explicitly by the tree structure.

Implementation of VivaVisualCode

The demo program VivaVisualCode is very simple. One can say that it provides the user interface to some functions of VivaCore library. For example, it allows you to type the text of a program to be parsed, to represent the built parse tree in a graphic form, to get additional information about the tree's nodes.

You may consider the details of its implementation in the source code of VivaVisualCode itself. The source code is open and you may modify and use it for your own purposes free.

User interface

Let's briefly consider the menu-items in VivaVisualCode application:

  • File -> Open i-file... - allows you to load a preprocessed i-file. Note: The program serves for demonstration purposes and is not intended for working with large files.
  • File -> Export Image - allows you to export the built parse tree into BMP file.
  • File -> Exit - to exit the program.
  • Code -> Edit Code - editing of input C++ code.
  • View -> List Mode. In VivaCore library the data are represented as binary trees. But logically the work is carried out over the lists. As the result there are auxiliary nodes implementing the lists on the basis of the tree. This menu item allows you to hide or show these auxiliary nodes.
  • View -> Close All - to minimize all the nodes
  • View -> Open All - to extend all the nodes.

After the program is loaded through "File->Open i-file..." or "Code->Edit Code" the parse tree will be shown on the screen. The nodes of the tree are colored differently depending on its type. Terminal nodes (leaves) show information about lexemes they represent. Terminal blocks are colored pink for lexemes which are C++ key words. Otherwise they are colored green to show that the lexemes are final leaves. The nodes of the high level contain names and number of branches.

You can also:

  • Scroll the window when the tree doesn't fit into the screen.
  • Minimize and extend the nodes (left mouse button).
  • Scale the image (Ctrl + mouse scroll wheel).
  • You can get additional information concerning each node by clicking the right mouse button on it (see figure 2).
a0025_VivaVisualCode/image3.png

Figure 2. View of encoded type for declaration of the class constructor.

Conclusion

Of course, the program we offer you is not sufficient to demonstrate all the abilities of VivaCore library and to show its potential scopes of use. But we hope that it will help you to master main work principles of VivaCore library.

We are always ready to communicate. Write us!

Popular related articles
The Evil within the Comparison Functions

Date: May 19 2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
Static analysis as part of the development process in Unreal Engine

Date: Jun 27 2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…
Appreciate Static Code Analysis!

Date: Oct 16 2017

Author: Andrey Karpov

I am really astonished by the capabilities of static code analysis even though I am one of the developers of PVS-Studio analyzer myself. The tool surprised me the other day as it turned out to be sma…
The Last Line Effect

Date: May 31 2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…
Free PVS-Studio for those who develops open source projects

Date: Dec 22 2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: Jul 31 2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…
Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities

Date: Nov 21 2018

Author: Andrey Karpov

A brief description of technologies used in the PVS-Studio tool, which let us effectively detect a large number of error patterns and potential vulnerabilities. The article describes the implementati…
PVS-Studio ROI

Date: Jan 30 2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
The Ultimate Question of Programming, Refactoring, and Everything

Date: Apr 14 2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: Oct 22 2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…

Comments (0)

Next comments
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept