|constatnt initialization firstname.lastname@example.org (2003-12-03)|
|Re: constatnt initialization email@example.com (2003-12-08)|
|Re: constatnt initialization firstname.lastname@example.org (Clint Olsen) (2003-12-13)|
|Re: constatnt initialization email@example.com (Nick Roberts) (2003-12-13)|
|Re: constatnt initialization firstname.lastname@example.org (Joachim Durchholz) (2003-12-14)|
|From:||Clint Olsen <email@example.com>|
|Date:||13 Dec 2003 21:01:06 -0500|
|Posted-Date:||13 Dec 2003 21:01:06 EST|
On 2003-12-04, Attila Csosz <firstname.lastname@example.org> wrote:
> constant name: type := expression;
> 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?
You're going to have to implement type equivalence checking to your
compiler. There are a couple of ways to do it. The brute force way
is to write a 'deep' comparison which recursively descends into 'type'
and compares it against 'expression' at each phase along the way to
determine that they are assignment compatible. This means, for
structs (records) comparing each field and ensuring that the number
and type of each field is compatible with each element in the
expression, comparing the subtype and number of elements for arrays,
and then simple checks for the intrinsic types (integer, real, string)
etc. You walk 'type' to help guide you for what to expect for
successive elements. If you're writing a recursive descent parser,
this is pretty straightforward since you'll build the 'type' before
you parse the expression.
There are more advanced ways of doing type equivalence using hash
tables (avoids deep compares), but the problem is that you may have to
coerce 'expression' to match the types specifically in 'type' if
you've already built the tree for 'expression'. This is common in
bottom-up techniques like in yacc and friends. I don't know VHDL that
well, so I don't know if type coercion is even allowed. If not, then
the 'expression' type will be correct by design and you can just
perform the deep compare as I mentioned in the first paragraph.
Return to the
Search the comp.compilers archives again.