Mini Java compiler (v)

Source: Internet
Author: User
Compiling VI, System design and implementation
This compiler is written in Java and is based on OO technology, so the whole system is designed as much as possible with Ood. The smallest design granularity in Ood is class, and the approximate class structure of the system is as follows




Compiler bag
The root of the entire system, the UML diagram is as follows:










Token bag
Encapsulates all the recognizable words, using a single code, and the corresponding code of the word is defined in the token class, which is an abstract class and is used only for inheritance. The UML diagram of the package is as follows:










Common Bag
Public packages that encapsulate some common objects and data structures:

The Hierarchytree class and the Hierarchytreenode class define the inheritance tree structure;

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)
Encapsulates the inheritance property between classes, using a n-directional tree on the data mechanism, which can be accessed directly by the parent node, or through the parent node directly by the child node.

Java does not support multiple inheritance, and Mini Java Connection Port inheritance (implements) is not supported, so there is only one parent node for each child node, and one parent node can have n child nodes.

Although not explicitly defined in the Mini Java specification, the implementation is modeled on Java to use the object class as the root node of the inheritance tree.

When implemented, a "pseudo tree" is defined, that is, the storage structure is a table, but the parent node and the leaf node are distinguished by additional level attributes.

Hierarchytreenode encapsulates the nodes, and Hierarchytree encapsulates some of the operations associated with the tree (insert, find).




Symbol tables (tokentable and identifier)
Because there are only a few situations where the identifier is defined, the class defined, or the method defined syntax error occurs:

A class with the same name declared in the same file

A method that declares the same name in the same class

class variables with the same name declared in the same class

A variable with the same name declared in the same method

A variable with the same name as the method parameter is declared in the

Therefore, I modified the content of the symbol table in the implementation, removed the "level" attribute, added "Belongsto" attribute, specifically defined see the third part of the Id_belongsto table.

The UML diagram for the common package is as follows:










Automation bag
The lexical analyzer and parser are encapsulated, and the UML diagram is as follows:








Exception bag
Encapsulates all the exceptions that can be thrown, as the UML diagram reads:








Identifier bag
Encapsulates all identifier classes, the class that implements the Typable interface has type attributes, and the UML diagram reads as follows:








Type Package
Encapsulates all types, provides the Factory () method in the type abstract class, generates type objects using simple factory (simplicity Factory) mode, and UML diagrams are as follows:








UI Package
Encapsulating the user interface




Classtreemodel
Inherit from Javax.swing.tree.TreeModel, you can display the contents of the inheritance tree in the graphical interface




Tokentablemodel
Inherits from Javax.swing.table.AbstractTableModel, the contents of the symbol table are displayed in the graphical interface




Memorytablemodel
Inherited from Javax.swing.table.AbstractTableModel, the contents of the Memory allocation table are displayed in the graphical interface

The UML diagram is as follows:








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.