dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]A step into c_grammar.y


From: Rhys Weatherley
Subject: Re: [DotGNU]A step into c_grammar.y
Date: Wed, 30 Oct 2002 08:54:44 +1000

minddog wrote:

> LINE 1:        | PostfixExpression '.' AnyIdentifier   {  // right here is
> something I am trying to modify for class attributes but looks like the
> oepration down on line 5
> LINE 2:                      $$ = ILNode_CMemberField_create
> (FixIdentifierNode($1, 0), $3);
>                         }
> LINE 3:        | K_INVOKE TYPE_NAME '.' AnyIdentifier '(' ')'  { // the same
> thing here , I want to put in PTR_OP too... but i noticed a different type of
> node creation...if it was the same as above, a CMemberField_create, i
> wouldn't be asking, but does this function pertain to any cross compat with
> Csharp code or just a reuse of a function?

In the C# compiler, "A.B" is always a member reference.  A member
can be a field, method, property, event, etc.  The semantic analysis
phase figures out what is actually happening and then replaces
the member reference with a field reference, method reference, etc.

In C, "." is used for accessing the fields of a struct or union.
That's where "CMemberField" comes in.  Since it doesn't need to
be replaced in semantic analysis, the actual node type is created
directly.

The K_INVOKE line is not actually part of ISO standard C.  It is
an extension to allow C# methods to be called from C.  The node
type "CSharpInvocation" is used for this purpose, because the
parser knows that it is an invocation at that point.

In short, if there is some ambiguity as to how a syntactic construct
should be interpreted, then create a generalized node type and fix
things up during semantic analysis.  But if the grammar can uniquely
determine what is going on, then create the final node type.

The K_INVOKE keyword is necessary in the C grammar because leaving
it out creates reduce/reduce conflicts.  C is a very nasty language
and adding syntax to it is very difficult.  C# gets away with the
overload of "." by pushing the intelligence into semantic analysis.

I hope this helps answer your questions.

Cheers,

Rhys.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]