Relvar syntax definition

This forum is for any questions about the language Tutorial D or the Rel implementation of it.
Post Reply
Chris Walton
Posts: 76
Joined: Sat Aug 18, 2012 2:13 pm

Relvar syntax definition

Post by Chris Walton » Sat Aug 18, 2012 2:26 pm

I have been looking at the syntax of Rel, and am having difficulty following the definition for RelVar. It defines var_relvar as:

var_relvar ::= ( <REAL> | <BASE> ) var_type_or_init_value var_keydeflist
| <PRIVATE> var_type_or_init_value var_keydeflist
| <PUBLIC> type_ref var_keydeflist
| <VIRTUAL> expression var_keydeflistoptional

[Ignoring for the purpose of this question, the alternative parts of this definition.]
The (<REAL> | <BASE>) and var_keydeflist make sense to me, but the var_type_or_init_value part seems, if followed through to define a single type definition. What I cannot see is how the attribute list for the relvar is defined. I expected it to be this part of the definition. As it does not appear to be the definition of the attribute list, what is it defining? and where is the attribute part of relvar definition?

I am assuming that it is my lack of understanding that is the problem, as I presume the documentation is derived from the parsing system.

Thanks for any light you can throw on this.

Chris Walton

Dave
Site Admin
Posts: 368
Joined: Sun Nov 27, 2005 7:19 pm

Re: Relvar syntax definition

Post by Dave » Tue Aug 21, 2012 6:47 pm

You wrote, "... the var_type_or_init_value part seems, if followed through to define a single type definition ..."

That is correct. A relvar can be defined by the keyword VAR, followed by a variable name, followed by REAL or BASE, followed by a relation type, followed by a key definition.

In other words, a relvar doesn't have attributes. A relvar has a relation type. The relation type has attributes.

So, for example, this is a relvar definition:

VAR myvar REAL RELATION {x CHAR, y INTEGER} KEY {x};

It consists of:

- "VAR myvar", which defines a variable of a given name;
- "REAL", which says we're going to create a persistent, relation-valued variable (i.e., a relvar) of the type following the keyword "REAL";
- A relation type - in this case, it's "RELATION {x CHAR, y INTEGER}";
- "KEY {x}" defines a key on attribute 'x' of the relation type that precedes it.

Chris Walton
Posts: 76
Joined: Sat Aug 18, 2012 2:13 pm

Re: Relvar syntax definition

Post by Chris Walton » Fri Aug 24, 2012 3:46 pm

Thanks for the explanation. I believe there is an English saying - there's none so blind as those who will not see. I could not see for looking.

Post Reply