feed visual metaphors to represent MATLAB/Octave
programs. The literature has already called attention
to this need. For example, in (Monteiro et al., 2010),
the authors provide a short review of the state-of-the-
art of aspect mining and particularly the identification
and localization of crosscutting concerns (CCCs) as
latent aspects. They conclude that until that time, not
enough attention was paid to this topic in the context
of MATLAB systems.
In the context of compilers in programming lan-
guages, a parser aims at analyzing the given sequence
of tokens to build a hierarchical data structure ac-
cording to previously established syntactic rules. In
most cases, the output of this transformation is a tree
structure, whose building process is carried out either
through top-down or bottom-up approaches. In the
first case, the tree is built from the root to the leaf
nodes, while in the bottom-up approach the flow is
in the opposite way (Aho et al., 2007). One of the
main advantages of the parser presented in this paper
is the conversion of source code of MATLAB/Octave
programs to KDM instances that can be subsequently
used to provide data to support the analysis and com-
prehension of target systems. In our case, we use the
data converted by the proposed parser to feed a soft-
ware comprehension visualization environment.
Parser Steps. Having this in mind, we developed the
parser in two steps. Step 1 comprises an intermedi-
ate parser capable of generating the AST of MAT-
LAB/Octave programs from its source code (parts A,
B and C of Figure 1). Step 2 comprises another partial
parser to generate KDM instances from AST (parts C,
D and E of Figure 1). In this case, part E shows the
data to be provided to software comprehension tools
to support program analysis.
To deal with several small differences between
MATLAB and Octave, we performed a prior analysis
of their grammars (Version 4.2.0 of the GNU Octave)
10
, the packages that comprise the KDM metamodel
and how the KDM metamodel can effectively repre-
sent MATLAB/Octave programs. This is a key issue
for the proposed parser presented in this paper.
During the language analysis phase (part A of Fi-
gure 1), the set of operations is identified, how they
work and which operators can be used. This inclu-
des arithmetic operators, comparison operators, bool-
ean expressions, function calls, assignment expressi-
ons, increment operators, and role definitions. Mo-
reover, several control structures (e.g., if, switch,
while, etc) and statements such as continue, break,
unwind, protect, try and continuation lines are also
considered. The ASTOctave library recognizes each
10
www.gnu.org/software/octave/doc/v4.2.0/
index.html#SEC Contents
of these operations, creates an element to represent
them and registers them as an AST node (part C of
the Figure 1). The version 4.2.0 of the GNU Octave
documentation
11
was used as a support for this imple-
mentation.
The analysis of the KDM metamodel was a requi-
rement to implement part D of Figure 1. More speci-
fically, we identified twelve packages from the KDM
metamodel whose elements aimed at representing a
specific part of the system under analysis. Packa-
ges from the KDM metamodel are defined in layers.
The Code package is the main package upon which
all the others provide their respective services. In
the Parser implementation described here, we use
elements from the five lower packages: Core, kdm,
Source, Code and Action. These elements where
then selected to be part of the XMI file to describe
the target system.
Considering all the steps presented in Fi-
gure 1 to convert MATLAB/Octave programs
to KDM instances, we implemented the follo-
wing five libraries ASTOctave, ASTOctaveToKDM,
OctaveKDMStructure, OctaveKDMToJSON and
OctaveKDMToXMI.
The first library of the pipeline is
ASTOctaveToKDM whose goal is to scan all the
source files from an Octave or MATLAB target
project. Library ASTOctaveToKDM is the central
mediator of the proposed set of libraries, being
responsible for instantiating the KDM representation
of the project to be parsed. It is also responsible
for controlling when and how other libraries are
instantiated and used. In this scenario, it instantiates
and calls library ASTOctave aimed at reading a MAT-
LAB or Octave file and generating the corresponding
AST. Library ASTOctave also creates the project’s
KDM metamodel. Library OctaveKDMStructure
represents the KDM structure of MATLAB and
Octave applications.
KDM Packages Description (OMG, 2016). Core:
Defines the basic elements to be used by all other
packages, including the entities, their relationships,
and the basic data types, such as String, Boolean,
and Integer. Therefore all other packages depend
on it but Core does not depend on any of them. These
basic data types are used to represent the KDM attri-
butes, their operations, and their parameters.
KDM: Defines key environment elements setting
the standards for building KDM views on the target
system. The elements described in this package, to-
gether with the elements described in Core, comprise
the KDM framework.
11
www.gnu.org/software/octave/doc/v4.2.0/
index.html#SEC Contents
A Parser and a Software Visualization Environment to Support the Comprehension of MATLAB/Octave Programs
181