Parsing VHDL program using Python

How to build an Abstract Syntax Tree from a VHDL program.

This is a part of a tree of syntactic dependencies in the VHDL EBNF-grammar .





System-on-a-Chip design refers to integrating large number of components of a digital computational system into a single integrated circuit. Complex electronic digital circuits are described formally using special programming languages called HDL (Hardware Description Language).

One of the most widespread and IEEE-standardized hardware description languages is VHDL. Its syntax is based on Ada, a programming language based on Pascal. VHDL is a structured, statically and strongly typed, imperative high-level programming language. It has constructs to handle the parallelism inherent in hardware designs. VHDL is widely used for hardware description,
hardware simulation, and hardware synthesis.

VHDL is a formal notation intended for use in all phases of the creation of electronic systems. Because it is both machine readable and human readable, it supports the development, verification, synthesis, and testing of hardware designs; the communication of hardware design data; and the maintenance, modification, and procurement of hardware.

Hardware synthesis means translation a program written in the form of a high-level human-readable programming language into a form of a low-level design of a electronic integrated circuit. Physical electronic circuit can then be produced on the basis of this low-level description, which is normally a netlist - a description of how different basic functional components are connected together. Hardware synthesis must operate under restrictions of a given set of functional components and under many other physical constraints.

A typical VHDL program for a hardware synthesis cannot use all resources allowed by the VHDL standard. It has to restrict its syntax and to use only simplest grammatic constructions, which could be recognized and could be mapped on a set of simple functions, e.g. on a set of binary logic functions. The task of synthesis is essentially more complex task than to build an executable processor-targeted code.

In order to extract a meaning from a program, it must be analyzed. First, its grammatic structure must be analyzed using a syntactic analysis. It is the process of analyzing a sequence of tokens to determine their grammatical structure with respect to a given formal grammar. Each token is a class of some text, where each lexeme is an instance of this class. For instance, following lexemes 1,2,3,4,5,6,7,8,9,0 are all of class DIGIT, it means that each occurrence of such lexeme in a program must be recognized as an instance of a class DIGIT, that is a token DIGIT to be formed.