Re: Why put type information into syntax?

Michael Spencer <michael.prqa@indigo.ie>
5 Apr 2000 22:17:26 -0400

          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)
Re: Why put type information into syntax? maratb@CS.Berkeley.EDU (Marat Boshernitsan) (2000-04-15)
Re: Why put type information into syntax? mspencer@eircom.net (Michael Spencer) (2000-04-15)
| List of all articles for this month |

From: Michael Spencer <michael.prqa@indigo.ie>
Newsgroups: comp.compilers
Date: 5 Apr 2000 22:17:26 -0400
Organization: Programming Research Limited
References: 00-03-133 00-03-146 00-04-017
Keywords: types, parse

Keith Thompson wrote:
>
> Michael Spencer <michael.prqa@indigo.ie> writes:
> > 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
> >
> > 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.
>
> It does? No offense, but are you speaking from experience?
>


Yes, although I'm most familiar with C++ parsing, not Java or C.
However, in any language I would hesitate to dismiss the keyword
status of an identifier and make up for it somehow later. Okay, maybe
in some languages you can safely group built-in type keywords with
user defined types. Though doing so, don't you make additional work
for yourself? As keywords, I would simply add rules to my grammar.
My parser generator does the rest. The parser verifies that built-in
types are used only in the proper context. I do not have to. I like
it when semantics are enforced automatically, it makes my life as a
parser developer that much easier. This is what I meant by a lot
cleaner. I would much rather add rules to my grammar than write code.


More importantly, in C++, the built-in type keywords prevent parse
conflicts. They do in my grammar. I am using a backtracking LR
parser generator to parse C++ (since I need infinite lookahead). So I
am guessing anyway on conflicts. But I take a slight penalty every
time I do so, so I do not want to guess more than I have to.


If you don't have to worry about conflicts, then it probably doesn't
really matter.


I'll say no more :)


Mike
michael.prqa@indigo.ie


Post a followup to this message

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