语义 - 句法 [英] Symantic - syntactic

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

问题描述

大家好,


任何人都可以提供一个代码片段,其中包含

在语法上正确但在语法上错误的构造。


C语言的语法也适用于

汇编的哪个阶段?

AFAIK以下是阶段 -


第一步:词法分析(Tokenizing> Parsing)

第二步:句法分析

第三步:语义分析

第四步:翻译单位。


我想知道实际上在syxytic分析步骤中涉及的内容



提前付款..

Hi all,

Can anyone please provide a code snippet containing a construct that
is syntactically correct but symantically wrong.

Also the grammar of the C language is applied at what stage of the
compilation?
AFAIK following are the stages -

Step I : Lexical Analysis ( Tokenizing > Parsing )
Step II : Syntactical Analysis
Step III : Symantic Analysis
Step IV : Translation of the unit.

I want to know actually what is involved in the synamtic analysis step
!

Thanx in advance..

推荐答案



" Nitin Bhardwaj" < NI ************* @ hotmail.com>在消息新闻中写道:17 ************************** @ posting.google.c om ...

"Nitin Bhardwaj" <ni*************@hotmail.com> wrote in message news:17**************************@posting.google.c om...
大家好,

任何人都可以提供一个代码片段,其中包含
在语法上正确但在语法上错误的构造。


以下我可能错了,但是试试吧。


{

int * p;

* p = 10;

}


语法正确,但语义错误。将10存储到

未初始化的位置与语法无关。然而,它在语义上是错误的,因为它没有任何意义。

C语言的语法也适用于编译的哪个阶段?


我相信语法分析。我认为编译器不需要进行语义分析。

AFAIK以下是各阶段 -

第一步:词法分析(令牌化>解析)
第二步:句法分析
第三步:语义分析第四步:翻译单位。

我想知道究竟什么是参与syxytic分析步骤


提前完成..
Hi all,

Can anyone please provide a code snippet containing a construct that
is syntactically correct but symantically wrong.
I may be wrong in the following in the following, but let''s try.

{
int *p;
*p = 10;
}

is syntactically correct, but sematically wrong. Storing 10 into an
uninitialized location has got nothing to do with the syntax. Whereas, it is
semantically wrong because it has no meaning.

Also the grammar of the C language is applied at what stage of the
compilation?
I believe at syntax analysis. I think semantic analysis is not required to
be performed by a compiler.
AFAIK following are the stages -

Step I : Lexical Analysis ( Tokenizing > Parsing )
Step II : Syntactical Analysis
Step III : Symantic Analysis
Step IV : Translation of the unit.

I want to know actually what is involved in the synamtic analysis step
!

Thanx in advance..




-

Vijay Kumar R Zanvar

我的主页 - http:// www .geocities.com / vijoeyz /


周五,2004年7月2日12:43:46 +0530,Vijay Kumar R Zanvar
< vi ***** @ globaledgesoft.com>写道:
On Fri, 2 Jul 2004 12:43:46 +0530, "Vijay Kumar R Zanvar"
<vi*****@globaledgesoft.com> wrote:

Nitin Bhardwaj < NI ************* @ hotmail.com>在消息新闻中写道:17 ************************** @ posting.google.c om ...

"Nitin Bhardwaj" <ni*************@hotmail.com> wrote in message news:17**************************@posting.google.c om...
大家好,

任何人都可以提供一个代码片段,其中包含一个语法正确但在语法上错误的构造。
Hi all,

Can anyone please provide a code snippet containing a construct that
is syntactically correct but symantically wrong.



我可能错了以下是以下内容,但我们试试吧。

{
int * p;
* p = 10;
}

语法正确,但语义错误。将10存储到未初始化的位置与语法无关。然而,它在语义上是错误的,因为它没有任何意义。



I may be wrong in the following in the following, but let''s try.

{
int *p;
*p = 10;
}

is syntactically correct, but sematically wrong. Storing 10 into an
uninitialized location has got nothing to do with the syntax. Whereas, it is
semantically wrong because it has no meaning.


C语言的语法也适用于
的哪个阶段。编译?

Also the grammar of the C language is applied at what stage of the
compilation?



我相信语法分析。我认为语义分析不需要由编译器执行。



I believe at syntax analysis. I think semantic analysis is not required to
be performed by a compiler.




我会说,从广义上讲,这就是它之间的区别。

编译器发出错误,因为代码语法错误,
或警告,因为代码可能是错误的,语义上的。


Jim



I would say, broadly speaking, that it''s the difference between the
compiler emitting an error, because the code is syntactically wrong,
or a warning, because the code might be wrong, semantically.

Jim


" Nitin Bhardwaj" < NI ************* @ hotmail.com>在留言中写道

news:17 ************************** @ posting.google.c om ...
"Nitin Bhardwaj" <ni*************@hotmail.com> wrote in message
news:17**************************@posting.google.c om...
大家好,

任何人都可以提供一个代码片段,其中包含
语法正确但语义合理的构造


语义上

错了。


int main()

{

int i;

int i;

返回0;

}

C语言的语法是否也适用于
编译的哪个阶段?


分析语法和语义时。

AFAIK以下是各个阶段 -

第一步:词法分析(Tokenizing>解析)
第二步:句法分析
第三步:语义分析第四步:翻译单位。
我想知道实际上syxytic分析步骤涉及的内容


语义

Hi all,

Can anyone please provide a code snippet containing a construct that
is syntactically correct but symantically
semantically
wrong.
int main()
{
int i;
int i;
return 0;
}
Also the grammar of the C language is applied at what stage of the
compilation?
When syntax and semantics are analyzed.
AFAIK following are the stages -

Step I : Lexical Analysis ( Tokenizing > Parsing )
Step II : Syntactical Analysis
Step III : Symantic Analysis
Step IV : Translation of the unit. I want to know actually what is involved in the synamtic analysis step
semantic
!



该标准没有定义''语义分析步骤''。它定义了

8''翻译阶段''。第7阶段的定义陈述了

(以及其他内容)令牌在语法和语义上的分析,

但不特别要求特定的订单或方法。 />

标准确定了词法元素的语义(即标记

和预处理标记),以及词汇子集的进一步语义

元素,例如关键字和标识符。


============================== ==================== ======================

ISO / IEC 9899:1999(E)

5.1.1.2翻译阶段


1翻译语法规则的优先顺序由

以下阶段(5)

1.物理源文件多字节字符以

实现定义的方式映射,如果需要

,则对源字符集

(引入行尾指标的换行符)。 Trigraph序列被相应的

单字符内部表示替换。


2.反斜杠字符的每个实例(\)紧随其后
删除新行字符
,拼接物理源

行以形成逻辑源行。只有最后一个反斜杠

任何物理源线都有资格成为

这样的拼接的一部分。非空的源文件应以

换行符结尾,在任何此类拼接发生之前,该字符不应紧跟

a反斜杠字符。


3.源文件被分解为预处理标记(6)和

空白字符序列(包括注释)。来源

文件不得以部分预处理令牌或部分

注释结束。每个注释都被一个空格字符替换。新行

字符被保留。是否保留或替换除了换行符之外的每个非空白字符序列 -

空格字符。

一个空格字符是实现定义的。

4.执行预处理指令,扩展宏调用
,执行
和_Pragma一元运算符表达式。如果与通用字符名称的语法匹配的字符

序列是由标记连接(6.10.3.3)生成的
,则行为为

undefined。

#include预处理指令导致命名的头或源

文件从阶段1到阶段4以递归方式处理。然后删除所有

预处理指令。


5.每个源字符集成员和字符转义序列

常量和字符串文字被转换为相应的

成员

的执行字符集;如果没有相应的成员,

它将被转换为实现定义的成员,而不是

null

(宽)字符。( 7)


6.相邻的字符串文字标记被连接起来。


7.分隔标记的空白字符不再重要。

每个预处理令牌都转换为令牌。由此产生的

令牌在语法和语义上进行分析并翻译为

a翻译单元。


8.所有外部对象和函数参考得到了解决。库

组件被链接以满足对函数的外部引用



当前翻译中未定义的对象。所有这样的翻译器

输出都被收集到一个程序映像中,其中包含在执行环境中执行所需的信息。


5 )实现应该表现得好像这些单独的阶段一样,甚至

虽然很多人通常在实践中折叠起来。


( 6)如6.4中所述,将源文件'

字符

分成预处理标记的过程与上下文有关。例如,请参阅

处理<在#include预处理指令中。


(7)实现不需要转换所有非对应的源

字符

到相同的执行角色。

===================================== ============= ======================

-Mike



The standard does not define a ''semantic analysis step''. It defines
eight ''phases of translation''. The definition of Phase 7 states
(among other things) "tokens are syntactically and semantically analyzed",
but does not specifically require a particular order or method.

The standard does define semantics for lexical elements (i.e. tokens
and preprocessing-tokens), and further semantics for subsets of lexical
elements, such as keywords and identifiers.

================================================== ======================
ISO/IEC 9899:1999 (E)

5.1.1.2 Translation phases

1 The precedence among the syntax rules of translation is specified by
the following phases (5)

1. Physical source file multibyte characters are mapped, in an
implementation-defined manner, to the source character set
(introducing new-line characters for end-of-line indicators) if
necessary. Trigraph sequences are replaced by corresponding
single-character internal representations.

2. Each instance of a backslash character (\) immediately followed
by a new-line character is deleted, splicing physical source
lines to form logical source lines. Only the last backslash on
any physical source line shall be eligible for being part of
such a splice. A source file that is not empty shall end in a
new-line character, which shall not be immediately preceded by
a backslash character before any such splicing takes place.

3. The source file is decomposed into preprocessing tokens (6) and
sequences of white-space characters (including comments). A source
file shall not end in a partial preprocessing token or in a partial
comment. Each comment is replaced by one space character. New-line
characters are retained. Whether each nonempty sequence of white-
space characters other than new-line is retained or replaced by
one space character is implementation-defined.

4. Preprocessing directives are executed, macro invocations are
expanded,
and _Pragma unary operator expressions are executed. If a character
sequence that matches the syntax of a universal character name is
produced by token concatenation (6.10.3.3), the behavior is
undefined.
A #include preprocessing directive causes the named header or source
file to be processed from phase 1 through phase 4, recursively. All
preprocessing directives are then deleted.

5. Each source character set member and escape sequence in character
constants and string literals is converted to the corresponding
member
of the execution character set; if there is no corresponding member,
it is converted to an implementation-defined member other than the
null
(wide) character.(7)

6. Adjacent string literal tokens are concatenated.

7. White-space characters separating tokens are no longer significant.
Each preprocessing token is converted into a token. The resulting
tokens are syntactically and semantically analyzed and translated as
a translation unit.

8. All external object and function references are resolved. Library
components are linked to satisfy external references to functions
and
objects not defined in the current translation. All such translator
output is collected into a program image which contains information
needed for execution in its execution environment.

5) Implementations shall behave as if these separate phases occur, even
though
many are typically folded together in practice.

(6) As described in 6.4, the process of dividing a source file''s
characters
into preprocessing tokens is context-dependent. For example, see the
handling of < within a #include preprocessing directive.

(7) An implementation need not convert all non-corresponding source
characters
to the same execution character.
================================================== ======================

-Mike


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

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