Re: constatnt initialization

Nick Roberts <nick.roberts@acm.org>
13 Dec 2003 21:03:40 -0500

          From comp.compilers

Related articles
constatnt initialization csosz77@axelero.hu (2003-12-03)
Re: constatnt initialization wbs@wschindler.net (2003-12-08)
Re: constatnt initialization clint@0lsen.net (Clint Olsen) (2003-12-13)
Re: constatnt initialization nick.roberts@acm.org (Nick Roberts) (2003-12-13)
Re: constatnt initialization joachim.durchholz@web.de (Joachim Durchholz) (2003-12-14)
| List of all articles for this month |
From: Nick Roberts <nick.roberts@acm.org>
Newsgroups: comp.compilers
Date: 13 Dec 2003 21:03:40 -0500
Organization: Compilers Central
References: 03-12-046
Keywords: analysis
Posted-Date: 13 Dec 2003 21:03:40 EST

Attila Csosz wrote:


> I'm working a VHDL (hardware description language)
> compiler/interpreter. The language has a complex type system (like
> Pascal).
>
> There are constant initialziation in format
>
> constant name: type := expression;
>
> My question: how to check that this can be assigned? I generate
> pseudo-code. The "type" can complex: like multidimensional arrays
> containing records. Can you draft me how do it?


Hi Attila,


I'm answering in case nobody else does. I may not be the best person
to answer your question, but I'll do my best. But I've got a few
questions.


What is your compiler/interpreter going to do? Is is going to simulate
circuits? What is the context of the project (is it your job)? In
which programming language are you implementing this
compiler/interpreter?


> I have the book Aho/Sethi/Ulmann: Compilers. Can you suggest me
> algorithms in this book for it or in the internet or other good
> books?


This is one of the 'canonical' compiler books, by all accounts, yet it
is one that I do not have! Nevertheless, I would imagine that if it
has a chapter on 'symbol tables' or something like (the main data
structures a typical compiler has inside it), this will be very
relevant to your question.


I am not an expert on VHDL -- although as it happens I am an expert on
Ada (its sibling language) -- but I gather that (unlike Ada) VHDL is a
'weakly typed' language: variables and expressions are considered to
'type match' if they are 'structurally identical' (rather than having
the same named type).


Assuming I'm right about this, I suggest you need to invent an
encoding of some kind that represents the structure of any variable or
expression. Probably this encoding will need to distinguish between
different major kinds of type (integer, float, array). If it is an
array, it will need to encode how many dimensions there are, and for
each dimension what the bounds are, in addition to the type of the
elements of the array.


For situations, such as an assignment (constant or not), where you
need to compare types, you compare these encodings. In essence, if the
encodings are the same, the types are the same.
--
Best of luck,
Nick Roberts


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.