newbie question: type checking

gbour@nomade.fr (guilaume bour)
8 Nov 2001 01:19:07 -0500

          From comp.compilers

Related articles
newbie question: type checking gbour@nomade.fr (2001-11-08)
Re: newbie question: type checking blume@research.bell-labs.com (Matthias Blume) (2001-11-08)
Re: newbie question: type checking christian.bau@cbau.freeserve.co.uk (Christian Bau) (2001-11-08)
| List of all articles for this month |

From: gbour@nomade.fr (guilaume bour)
Newsgroups: comp.compilers
Date: 8 Nov 2001 01:19:07 -0500
Organization: http://groups.google.com/
Keywords: types, question
Posted-Date: 08 Nov 2001 01:19:07 EST

Hello. I have to invent a language and write its compiler(which must
generate c-shell) for a school project.


My idea is to made a language with no type declaration, and where a
variable
could take different types during its "life".
But I want also to make a compiler with strong type checking
(the type of all variables must be known after compilation).


here is an exemple:
    a := 5
    b := a + 3


    b := "hello"


We can determine b type by using the context:
* line 2: b is an integer
                    (it result from the addition of a(an integer) and 3(an
integer too))
* line 4: b becomes a string




In the next example, we can't determine the type of the variable 'res'
after the instruction 'if' (it can be a string as well as a float):


    read(div)
    if(div = 0)
        res := "division by 0"
    else
        res := 4/div
    endif




So I would like to know if there is a way to avoid(even suppress) such
ambiguity.


regards.
Guillaume Bour.



Post a followup to this message

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