Re: Why put type information into syntax?

Tim Harris <tlh20@cam.ac.uk>
1 Apr 2000 14:05:16 -0500

          From comp.compilers

Related articles
Why put type information into syntax? across@vega.co.uk (Allister Cross) (2000-03-25)
Re: Why put type information into syntax? michael.prqa@indigo.ie (Michael Spencer) (2000-03-28)
Re: Why put type information into syntax? lex@cc.gatech.edu (2000-03-28)
Re: Why put type information into syntax? RobertADuffbobduff@world.std.com> (2000-03-28)
Re: Why put type information into syntax? tlh20@cam.ac.uk (Tim Harris) (2000-04-01)
Re: Why put type information into syntax? kst@cts.com (Keith Thompson) (2000-04-01)
Re: Why put type information into syntax? michael.prqa@indigo.ie (Michael Spencer) (2000-04-05)
Re: Why put type information into syntax? rod.bates@wichita.boeing.com (Rodney M. Bates) (2000-04-05)
Re: Why put type information into syntax? kst@cts.com (Keith Thompson) (2000-04-11)
Re: Why put type information into syntax? idbaxter@semdesigns.com (Ira D. Baxter) (2000-04-14)
Re: Why put type information into syntax? world!bobduff@uunet.uu.net (Robert A Duff) (2000-04-14)
[2 later articles]
| List of all articles for this month |

From: Tim Harris <tlh20@cam.ac.uk>
Newsgroups: comp.compilers
Date: 1 Apr 2000 14:05:16 -0500
Organization: University of Cambridge Computer Laboratory
References: 00-03-133 00-03-146
Keywords: types, parse

Allister Cross wrote:
>> Does anyone know of any reasons why built-in type names should be
>> incorporated in the syntax of a language. I have been looking at the


Michael Spencer <michael.prqa@indigo.ie> wrote:
>I can think of two reasons, first, in C and C++ I know, built-in type
>names are keywords. By enforcing this rule in the grammar your parser
>becomes a lot cleaner. Also, conveniently, by treating them as
>keywords you can prevent parse conflicts.


Here is a similar peculiarity from Java:


            class A
            {
                    void f ()
                    {
                          long A = 42;
                          System.out.println ((A)-1); /*VAR*/
                          System.out.println ((long)-1); /*TYPE*/
                    }
            }


At /*VAR*/ "(A)" is an expression returning the value of the local
variable "A". Coincidentally "A" is also the name of the class being
defined.


At /*TYPE*/ "(long)" is a cast from integer to long.


I would be surprised if these two constructs could be handled in the
same way in the grammar without adding extra complexity to later
phases.


Tim


Post a followup to this message

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