Mini Java Compiler (5)

xiaoxiao2021-03-06  19

Six, system design and implementation

This compiler is written by Java, based on OO technology, so the entire system is designed with OOD. The smallest design granularity in OO is class, and the general structure of this system is as follows.

Compiler package

The root of the entire system, the UML map is as follows:

Token bag

Encapsled all recognizable words, using a synerg, the word corresponding to the code is defined in the Token class, which is an abstract class, which is for inheritance. The package UML map is as follows:

Common package

Public package, encapsulates some common objects and data structures:

The Hierarchytree class and the Hierarchytreenode class define inherited tree structures;

The MemoryTable class and the Memorycell class define the required memory allocation table;

The LOCATABLE interface and the Locator class define the locator;

TOKENTABLE defines the symbol table;

Inheritance tree (hierarchytreenode and hierarchytree)

The inheritance attribute between the encapsulation class uses an N-fork bidirectional tree on the data mechanism, and the child node can be directly accessed by the parent node, or the parent node can also be accessed directly from the child node.

Java does not support multi-inheritance, and the MINI Java connection port inheritance is not supported, so there is only one parent node for each child node, and a parent node can have N subtitches.

Although there is no clear definition in the MINI Java specification, it is realized that the Object class is the root node of the inherited tree in accordance with Java.

A "pseudo tree" is defined when the implementation is defined, ie the storage structure is a table, but the parent node and the leaf junction point are distinguished by additional Level attribute.

Hierarchytreenode encapsulates nodes, Hierarchytree encapsulates some operations related to the tree (insert, lookup).

Symbol table (tokenable and ideifier)

Because only the following cases occur, "identifier has defined", "class defined" or "method defined" syntax error:

A class that declares the same name in the same file

Method for declaring the same name in the same class

Declare the same name of the same name in the same class

Declaring variables of the same name in the same method

Method declared the same variables as the method parameter name

So I modified the contents of the symbol table when I realized it, and I dropped the "Level" attribute, add the "BelongSto" property, and see the ID_belongsto table of the third part.

The UML chart of the COMMON package is as follows:

AUTOMATION package

Encapsulated the lexical analyzer and grammar analyzer, the UML map is as follows:

EXCEPTION package

The UML map is encapsulated, the UML map is as follows:

Identifier package

Encaps all identifier categories, implement the type attribute of the Typable interface, the UML map is as follows:

Type package

Encapsulated all types, provide a Factory () method in the Type abstract class, generate type objects using simple factory (Simple Factory) mode, UML maps are as follows:

UI package

Package user interface

ClasStreeModel

Inherited from javax.swing.tree.treemodel, display the content of the inherited tree in the graphical interface

TokentableModel

Inherited from javax.swing.table.abstractTableModel, the contents of the symbolic table is displayed in the graphical interface

MemoryTableModel

Inherited from javax.swing.table.abstractTableModel, the content of the memory allocation table is displayed in the graphical interface

The UML map is as follows:

转载请注明原文地址:https://www.9cbs.com/read-46672.html

New Post(0)