Related articles |
---|
Implementation decision trimaran@uni-paderborn.de (Michael Risse) (1998-09-22) |
Re: Implementation decision dwight@pentasoft.com (1998-09-22) |
Re: Implementation decision qjackson@wave.home.com (Quinn Tyler Jackson) (1998-09-26) |
Re: Implementation decision mck@pobox.com (Michael McKernan) (1998-09-26) |
From: | "Quinn Tyler Jackson" <qjackson@wave.home.com> |
Newsgroups: | comp.compilers |
Date: | 26 Sep 1998 01:06:52 -0400 |
Organization: | Compilers Central |
References: | 98-09-103 |
Keywords: | design, types |
>In declarations we have typespecifiers such as 'void', 'float',
>'int', 'unsigned' etc. The programmer is not allowed to use these
>things in any desired combination. There are some constraints.
>My question is: How to implement these constraints ?
>
>We can build some (or all?) of the constraints in the grammar.
>This would result in a much bigger grammar.
Always one to like to jazz around, I decided to see for myself what
would be involved in putting the constraints in the grammar entirely
by writing (an admittedly overly simplified) grammar that would deal
with delcarations in the following forms:
const unsigned int i;
unsigned u;
signed char c;
char c;
const static unsigned c;
but not the following:
unsigned static i;
I realize that the grammar doesn't deal with the perfectly legal case
of:
static const char c;
but it could with some work. What does it prove? I can imagine that
an entirely grammar driven system of constraints would quickly become
much more convoluted than what follows.... especially if were to
handle all legal cases correctly (which mine doesn't by far).
// grammar begins
/*
Jazzing around -- Visual Parse++ format
*/
%expression main
'[a-zA-Z]+' id;
'[ \t\r\n]+' %ignore;
';' semicolon, ';';
'const' const;
'volatile' volatile;
'static' static;
'unsigned' unsigned;
'signed' signed;
'char' char;
'int' int;
'float' float;
'double' double;
%production S
S_0 S -> ;
S_1 S -> decl S;
decl_0 decl -> spec simple id ';' ;
decl_1 decl -> spec compound id ';' ;
decl_2 decl -> ';' ;
spec_0 spec -> ;
spec_1 spec -> const;
spec_2 spec -> storage;
spec_3 spec -> const storage;
storage_0 storage -> static;
storage_2 storage -> volatile;
simple_0 simple -> ; // implied int
simple_1 simple -> numeric;
compound_0 compound -> sign_mod numeric;
compound_1 compound -> sign_mod;
sign_mod_0 sign_mod -> signed;
sign_mod_1 sign_mod -> unsigned;
numeric_0 numeric -> char;
numeric_1 numeric -> int;
numeric_2 numeric -> float;
numeric_3 numeric -> double;
// grammar ends
--
Quinn Tyler Jackson
email: qjackson@wave.home.com
url: http://www.qtj.net/~quinn/
ftp: qtj.net
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.