C#2.0语言语法 [英] C# 2.0 language grammar

查看:55
本文介绍了C#2.0语言语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我对C#

2.0规范的语言语法的正确性有疑问。我正在使用2005年6月

ECMA-334标准中指定的语法。


基本上,using-namespace-directive的定义如下:


using-namespace-directive:

using namespace-name;


namespace-name:

namespace-or-type-name

namespace-or-type-name:

identifier type-argument-list(opt)

...


type-argument-list:

<类型>


请注意,上述作品允许此声明合法(即使它是
不是
语义上有意义):


使用System< int> ;;


显然,在这种情况下,这并不具有语义意义。我想知道

为什么

a新产品没有专门针对这种情况而被引入

使用指令提供的语义信息本身不要

允许类型参数列表(可选当然意味着它可能存在)。

有什么想法吗?


谢谢!

-

Magius

解决方案

来自Sectin 10.8:


"如下所述的解决方案,

名称空间名称的名称空间或类型名称应指

命名空间,否则发生编译时错误。类型参数

(§25.5.1)不应出现在

名称空间名称中(只有类型可以有类型参数)。

type-name是引用类型的namespace-or-type-name。如下所述

分辨率,类型名称的

名称空间或类型名称应引用类型,否则为
$ b发生$ b编译时错误。


查询的目的究竟是什么?难道你不期望那么多吗?b b b高素质的人在你看过之前已经修改了这个规格吗?


-

HTH,


Kevin Spencer

Microsoft MVP

..Net开发人员

Ambiguity有它具有一定的品质。


" Magius" <马**** @ discussions.microsoft.com>在消息中写道

news:36 ********************************** @ microsof t.com ...

您好,

我对C#
2.0规范的语言语法的正确性有疑问。我正在使用6月
2005 ECAZ-334标准中规定的语法。

基本上,using-namespace-directive的定义如下:

using-namespace-directive:
using namespace-name;

namespace-name:
namespace-or-type-name

名称空间-or-type-name:
标识符类型-argument-list(opt)


type-argument-list:
<类型>

请注意,上述作品允许此声明合法(即使
它在语义上没有意义):

使用System< int>;

显然,在这种情况下,这并不具有语义意义。我想知道
为什么没有专门针对这种情况引入新产​​品,因为
反对使用指令本身提供的语义信息而不是
允许类型参数列表(可选当然意味着它可能存在)。
有什么想法吗?

谢谢!
-
Magius



当然我希望有足够的高素质人士审查

规范,这不是重点。我的问题只是为什么命名空间名称

引用了命名空间或类型名称而不是简单地执行:


namespace-name:

标识符

qualified-alias-member

namespace-name。标识符


在规范中提供的语法中,生成包含文档中其他位置存在的语义

信息,而不是

自我描述。这更像是一个学术性和好奇心的问题,而不是任何实际用途。


-

Magius

" Kevin Spencer"写道:

来自Sectin 10.8:

"按照下面的描述,
命名空间的名称空间或类型名称 - name应引用
命名空间,否则会发生编译时错误。类型参数
(?§25.5.1)不应出现在
名称空间名称中(只有类型可以有类型参数)。
类型名称是名称空间或类型-name引用类型。如下所述解决
后,类型名称的名称空间或类型名称应引用类型,否则会发生编译时错误。

您查询的目的究竟是什么?难道你不期望那些高素质的人在你看过之前已经修改了这个规范吗?

-
HTH,

Kevin Spencer
微软MVP
..Net开发人员
歧义具有一定的品质。

Magius <马**** @ discussions.microsoft.com>在消息中写道
新闻:36 ********************************** @ microsof t.com。 ..

您好,

我对C#
2.0规范的语言语法的正确性有疑问。我正在使用6月
2005 ECAZ-334标准中规定的语法。

基本上,using-namespace-directive的定义如下:

using-namespace-directive:
using namespace-name;

namespace-name:
namespace-or-type-name

名称空间-or-type-name:
标识符类型-argument-list(opt)


type-argument-list:
<类型>

请注意,上述作品允许此声明合法(即使
它在语义上没有意义):

使用System< int>;

显然,在这种情况下,这并不具有语义意义。我想知道
为什么没有专门针对这种情况引入新产​​品,因为
反对使用指令本身提供的语义信息而不是
允许类型参数列表(可选当然意味着它可能存在)。
有什么想法吗?

谢谢!
-
Magius




Magius,


我提前为劫持你的帖子而道歉,但我的问题是

有点相关。我注意到using指令

的行为会有所不同,具体取决于它在1.1版中的位置。几个月前我发布了

,但我从来没有得到满意的答复。为什么

的行为是不同的?它在规范中提到了什么?

我没有看到ECMA规范第16.3节中提到的任何内容。

2.0是否有这样的表现?例如:


//以下行导入命名空间B类型(Bar1& Bar2)。

使用B;

命名空间ACD

{

//以下行导入命名空间AB类型(Foo1& Foo2)。

使用B;

}


名称空间AB

{

公共类Foo1 {}

public class Foo2 {}

}


命名空间B

{

公共类Bar1 {}

公共类Bar2 {}

}


Brian


Magius写道:< blockquote class =post_quotes>你好,

我对C#
2.0规范的语言语法的正确性有疑问。我正在使用2005年6月ECMA-334标准中规定的语法。

基本上,using-namespace-directive的定义如下:

using -namespace-directive:
using namespace-name;

namespace-name:
namespace-or-type-name

namespace-or-type -name:
标识符类型 - 参数列表(opt)
...

类型参数列表:
<类型>

请注意,上述作品允许此声明合法(即使它在语义上没有意义):
使用System< int>;

显然,在这种情况下,这并不具有语义意义。我想知道为什么没有专门针对这种情况引入新产​​品,而不是使用指令本身提供的语义信息来不允许类型 - 参数列表(可选当然意味着它可以在那里)。
任何想法?

谢谢!
-
Magius




Hello,

I have a question about the correctness of the language grammar for the C#
2.0 specification. I am working with the grammar specified in the June 2005
ECMA-334 standard.

Basically, a using-namespace-directive is defined as follows:

using-namespace-directive:
using namespace-name ;

namespace-name:
namespace-or-type-name

namespace-or-type-name:
identifier type-argument-list (opt)
...

type-argument-list:
< type >

Note that the above productions allow this statement to be legal (even if it
doesn''t
semantically make sense):

using System<int>;

Obviously, this doesn''t make semantic sense in this context. I''m wondering
why
a new production was not introduced specifically for this context as opposed
to using the semantic information provided by the directive itself to not
allow the type-argument-list (optional of course means it could be there).
Any thoughts?

Thanks!
--
Magius

解决方案

From Sectin 10.8:

"Following resolution as described below, the namespace-or-type-name of a
namespace-name shall refer to a
namespace, or otherwise a compile-time error occurs. Type arguments
(§25.5.1) shall not be present in a
namespace-name (only types can have type arguments).
A type-name is a namespace-or-type-name that refers to a type. Following
resolution as described below, the
namespace-or-type-name of a type-name shall refer to a type, or otherwise a
compile-time error occurs."

What exactly is the purpose of your query? Wouldn''t you expect that enough
highly-qualified people have reviiewed this spec before you looked it over?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Magius" <Ma****@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...

Hello,

I have a question about the correctness of the language grammar for the C#
2.0 specification. I am working with the grammar specified in the June
2005
ECMA-334 standard.

Basically, a using-namespace-directive is defined as follows:

using-namespace-directive:
using namespace-name ;

namespace-name:
namespace-or-type-name

namespace-or-type-name:
identifier type-argument-list (opt)
...

type-argument-list:
< type >

Note that the above productions allow this statement to be legal (even if
it
doesn''t
semantically make sense):

using System<int>;

Obviously, this doesn''t make semantic sense in this context. I''m
wondering
why
a new production was not introduced specifically for this context as
opposed
to using the semantic information provided by the directive itself to not
allow the type-argument-list (optional of course means it could be there).
Any thoughts?

Thanks!
--
Magius



Of course I expect that enough highly-qualified people have reviewed the
spec, that is not the point. My question was simply why a namespace-name
referred to a namespace-or-type-name rather than simply doing:

namespace-name:
identifier
qualified-alias-member
namespace-name . identifier

In the grammar as presented in the spec, the production carries semantic
information that is present elsewhere in the document as opposed to being
self-describing. It was more a question of academic nature and curiosity
rather than serving any practical use.

--
Magius
"Kevin Spencer" wrote:

From Sectin 10.8:

"Following resolution as described below, the namespace-or-type-name of a
namespace-name shall refer to a
namespace, or otherwise a compile-time error occurs. Type arguments
(?§25.5.1) shall not be present in a
namespace-name (only types can have type arguments).
A type-name is a namespace-or-type-name that refers to a type. Following
resolution as described below, the
namespace-or-type-name of a type-name shall refer to a type, or otherwise a
compile-time error occurs."

What exactly is the purpose of your query? Wouldn''t you expect that enough
highly-qualified people have reviiewed this spec before you looked it over?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Magius" <Ma****@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...

Hello,

I have a question about the correctness of the language grammar for the C#
2.0 specification. I am working with the grammar specified in the June
2005
ECMA-334 standard.

Basically, a using-namespace-directive is defined as follows:

using-namespace-directive:
using namespace-name ;

namespace-name:
namespace-or-type-name

namespace-or-type-name:
identifier type-argument-list (opt)
...

type-argument-list:
< type >

Note that the above productions allow this statement to be legal (even if
it
doesn''t
semantically make sense):

using System<int>;

Obviously, this doesn''t make semantic sense in this context. I''m
wondering
why
a new production was not introduced specifically for this context as
opposed
to using the semantic information provided by the directive itself to not
allow the type-argument-list (optional of course means it could be there).
Any thoughts?

Thanks!
--
Magius




Magius,

I apologize in advance for hijacking your thread, but my question is
slightly related. I noticed that the behavior of the using directive
is different depending on where it is placed in version 1.1. I posted
this several months ago, but I never got a satisfactory response. Why
is the behavior different? Where is it mentioned in the specification?
I didn''t see any mention of it section 16.3 of the ECMA specification.
Does 2.0 behave this way? For example:

// The following line imports namespace B types (Bar1 & Bar2).
using B;
namespace A.C.D
{
// The following line imports namespace A.B types (Foo1 & Foo2).
using B;
}

namespace A.B
{
public class Foo1 { }
public class Foo2 { }
}

namespace B
{
public class Bar1 { }
public class Bar2 { }
}

Brian

Magius wrote:

Hello,

I have a question about the correctness of the language grammar for the C#
2.0 specification. I am working with the grammar specified in the June 2005
ECMA-334 standard.

Basically, a using-namespace-directive is defined as follows:

using-namespace-directive:
using namespace-name ;

namespace-name:
namespace-or-type-name

namespace-or-type-name:
identifier type-argument-list (opt)
...

type-argument-list:
< type >

Note that the above productions allow this statement to be legal (even if it
doesn''t
semantically make sense):

using System<int>;

Obviously, this doesn''t make semantic sense in this context. I''m wondering
why
a new production was not introduced specifically for this context as opposed
to using the semantic information provided by the directive itself to not
allow the type-argument-list (optional of course means it could be there).
Any thoughts?

Thanks!
--
Magius




这篇关于C#2.0语言语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆