Re: type definitions

Justin Hibbits <hibbits@cme.nist.gov>
24 May 2003 20:26:52 -0400

          From comp.compilers

Related articles
type definitions hibbits@cme.nist.gov (Justin Hibbits) (2003-05-18)
Re: type definitions bear@sonic.net (2003-05-23)
Re: type definitions hibbits@cme.nist.gov (Justin Hibbits) (2003-05-24)
Re: type definitions cfc@world.std.com (Chris F Clark) (2003-05-29)
| List of all articles for this month |
From: Justin Hibbits <hibbits@cme.nist.gov>
Newsgroups: comp.compilers
Date: 24 May 2003 20:26:52 -0400
Organization: Case Western Reserve University, Cleveland, OH, USA
References: 03-05-151 03-05-171
Keywords: types
Posted-Date: 24 May 2003 20:26:52 EDT

bear@sonic.net wrote:
> Justin Hibbits wrote:
>
>
>>I'm working on a compiler library, and extensions to yacc to allow
>>people to easily write language definitions, and build compilers with
>>very little C code in the definition/grammar. But, I'm stuck, and
>>can't figure out how to cleanly represent type definitions using a
>>yacc-like syntax, so that one only has to write "set_type( TYPE_NAME )"
>>in order to set the type, and perform sanity checking (making sure
>>types don't conflict, types aren't specified more than allowed, etc).
>
>>...I want to make my compiler as source-language independant as
>>possible...
>
>
> "I'm afraid I don't have a solution for you, but I admire the
> problem." In this case, I'm reasonably sure a good solution exists,
> but the problem may be more complex than you're giving it credit for.
>
> Have you considered the many languages where it is values that have
> types rather than variables? In scheme/lisp/most functional languages,
> a value of any type may be assigned to any variable. Or languages
> like Python, where the variables have type unions (Where each variable
> has a set of types and may be assigned only values of those types)?
> Or even languages like FORTH-1, where variables don't even exist?
> Everything is done with values on the stack and strongly-typed
> functions.


Yes I have. I'm not imposing anything on the grammar writer, because
'type' becomes an attribute, rather than a complete definition. In
the case of the functional languages, you can assign the type
attribute to the value, and tell the compiler not to perform strict
type checking at compile time, and just delay it for the runtime
environment or insert code to do it (similar to objective-C).


Anyway, a couple days ago, I got an idea to eliminate strict type
definitions, and assign them as attributes. I came up with the
following syntax (someone tell me if I should add something. It seems
to work nicely for C, maybe C++ and objective C, but not too sure
about others):


%datatype TYPE_IDENTIFIER (what the program refers to it as) {
name<"quoted name"> // may never be used
type<builtin_type> // char, int, real
size<builtin_size> // long, short, byte, bit, expression (like 2*byte)
modifies<TYPE_IDENTIFER_MODIFIED> // can have several of these
attribute<attached_attribute> // anything you want it to be, language
specific
};


all fields except name are optional, and type, size, and attribute, at
least one of them must be specified in order for the compiler to
understand what the datatype does


If you can think of anything to add, just let me know, so that I can add it.


-Justin


Post a followup to this message

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