21.01.2022 Views

Sommerville-Software-Engineering-10ed

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

190 Chapter 6 ■ Architectural design

Lexical

analyzer

Syntax

analyzer

Semantic

analyzer

Formatter

Abstract

syntax tree

Grammar

definition

Optimizer

Figure 6.21 A

repository architecture

for a language

processing system

Editor

Symbol

table

Repository

Output

definition

Code

generator

program to be executed, and a translator converts these into instructions for an abstract

machine. These instructions are then interpreted by another component that fetches

the instructions for execution and executes them using (if necessary) data from the

environment. The output of the process is the result of interpreting the instructions on

the input data.

For many compilers, the interpreter is the system hardware that processes machine

instructions, and the abstract machine is a real processor. However, for dynamically

typed languages, such as Ruby or Python, the interpreter is a software component.

Programming language compilers that are part of a more general programming

environment have a generic architecture (Figure 6.21) that includes the following

components:

1. A lexical analyzer, which takes input language tokens and converts them into an

internal form.

2. A symbol table, which holds information about the names of entities (variables,

class names, object names, etc.) used in the text that is being translated.

3. A syntax analyzer, which checks the syntax of the language being translated. It

uses a defined grammar of the language and builds a syntax tree.

4. A syntax tree, which is an internal structure representing the program being

compiled.

5. A semantic analyzer, which uses information from the syntax tree and the symbol

table to check the semantic correctness of the input language text.

6. A code generator, which “walks” the syntax tree and generates abstract

machine code.

Other components might also be included that analyze and transform the syntax

tree to improve efficiency and remove redundancy from the generated machine code.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!