Introdução ao Desenvolvimento de Compiladores

From Wiki**3

Revision as of 15:16, 13 April 2015 by Root (talk | contribs)

Compiladores
Introdução ao Desenvolvimento de Compiladores
Aspectos Teóricos de Análise Lexical
A Ferramenta Flex
Introdução à Sintaxe
Análise Sintáctica Descendente
Gramáticas Atributivas
A Ferramenta YACC
Análise Sintáctica Ascendente
Análise Semântica
Geração de Código
Tópicos de Optimização

Our approach to compiler development follows the classical structure based on a workflow that starts with lexical analysis, followed by syntactic analysis, semantic analysis, and code generation. The mentioned steps are based on two code generators (one for creating the scanner and another for creating the syntactic parser) and on modules manually written by the programmer.

Even though we use the classical versions of the scanner and parser generators (Flex and BYACC), we do not use the C language. Rather, we use C++. Furthermore, we do not limit ourselves to switching languages and programming a number of classes. We make full use of object-oriented programming and structures driven by design patterns to achieve a compiler that is simultaneously cleanly organized and easy to understand and change. These are crucial aspects, both in what concerns programming effort and didactic objectives.

Regarding C++

Using C++ is not only a way of ensuring a "better C", but also a way of being able to use OO architecture principles in a native environment (the same principles could have been applied to C development, at the cost of increased development difficulties). Thus, we are not interested only in taking a C++ compiler, our old C code, and "hope for the best". Rather, using C++ is intended to impact every step of compiler development, from the organization of the compiler as a whole to the makeup of each component.

Using C++ is not only a decision of what language to use to write the code: it is also a matter of who or what writes the compiler code. If, for a human programmer, using C++ is just a matter of competence, tools that generate some of the compiler's code must be chosen carefully so that the code they generate works as expected.

Some of the most common compiler development support tools already support C++ natively. This is the case of the Flex lexical analyser or the Bison parser generator. Other tools, such as Berkeley YACC (BYACC) support only C. In the former case, the generated code and the objects it supports have only to be integrated into the architecture; in the latter case, further adaptation may be needed, either by the programmer or through specialized wrappers. BYACC-generated parsers, in particular, as will be seen, although they are C code, are simple to adapt to C++.

Regarding Design Patterns

Going beyond basic OO principles into the world of design patterns is just a small step, but one that contributes much of the overall gains in this change: indeed, effective use of a few choice design patterns -- especially, but not necessarily limited to, the composite and visitor design patterns -- contributes to a much more robust compiler and a much easier development process.