表达和陈述的定义。 [英] Definition of expression and statement.
问题描述
嗨!
单词expression和陈述经常在C99和C-
教科书中使用,但是,我不确定这些
关于C语言的明确定义。
有人可以提供明确的表达定义吗?和
声明?表达式和
语句之间有什么区别?
这是我发现的(教科书和自己的结论),请
纠正if / where错误。
----------------------------- --------------------
表达式是:
表达式包含数据或没有数据。 />
每个表达式都有一个类型,如果类型不是void,则为一个值。
表达式可以包含零个或多个操作数,零个或多个
运算符。
最简单的表达式由单个常量,变量或
a函数调用组成。
表达式可以包含赋值。
表达式永远不会包含分号。
表达式可以与其他表达式结合形成更复杂的
表达式。
表达式可以作为操作数。
如果分号被删除,语句将成为表达式
(块状态不适用)但是,
在分号
之后立即开始并在下一个分号之前结束的表达式的值总是被丢弃。
例子:
4 * 512 //输入:int。价值:2048。
printf("一个例子!\ n)//类型:int值:无论从
返回什么
printf。
1.0 + sin(x)//类型:double值:无论是什么是
表达式的结果。
srand((无符号)时间(NULL))/ /类型:无效。值:无。
(int *)malloc(sizeof(int))//类型:int *。价值:malloc返回的地址
。
1 ++ //类型:int。价值:2,对吗?
a ++ //类型:取决于a。价值:一个多于一个。
x = 5 //类型:取决于变量x的类型,对吗?价值:5。
2 * 32767 //类型:取决于INT_MAX,对吗?价值:65534
问题:上面表达式的类型是什么?
a //类型:取决于a。价值:取决于a。
1 //类型:int。值:1
f()//类型:取决于f()的返回类型。价值:取决于什么
f()返回。
对吗?
在上面的表达式值中表达式是抛出
远,对吗?
表达式的更多例子与
$ b不同/变体$ b以上的例子?
--------------------------------- ----------------
声明是:
任何以分号分隔的内容,除非它是'aa for语句中的声明或
表达式。
语句指定要执行的操作,例如操作或
函数调用。 br />
语句是程序结构,后跟分号。
执行的表达式是一个语句,对吗?
语句没有值或者类型。
语句指定要执行的操作,例如函数调用的
算术运算。
Everey语句是不是块以分号结束。
语句总是原子,即声明不能被破坏
到sub陈述。
以下是陈述:
作业(=)
化合物({...})
休息
继续
goto
标签
如果
,则和对于
返回
开关
语句示例:
以上所有表达式都将成为语句当分号是
添加到表达式时。
问题:是否可以使用分号进行声明,
$ b $当分号被删除时b不会成为表达式
吗?
------------------ -------------------------------
此外,
表达式语句的定义是什么,它与语句和表达式有什么不同?
它只是一个后跟分号的表达式。
块语句的定义是什么?
是否只是花括号中的一个或多个语句?
BRs!
" dspfun"写道:
单词expression和陈述经常在C99和C-
教科书中使用,但是,我不确定这些
关于C语言的明确定义。
有人可以提供明确的表达定义吗?和
声明?表达式和
语句之间有什么区别?
我认为唯一真正清晰的定义来自对BNF的研究,即b / b
语言。 (BNF - Backus Normal From / Backus Naur表格。)你有没有?b $ b试过维基百科?
dspfun写道:
嗨!
单词expression和陈述经常在C99和C-
教科书中使用,但是,我不确定这些
关于C语言的明确定义。
有人可以提供明确的表达定义吗?和
声明?表达式和
语句之间有什么区别?
第6.5p1节说:
" __expression_是一系列运算符和操作数,指定
计算一个值,或者指定一个对象或一个函数,或者生成副作用或者执行它们组合的
。
第6.8p2节说:
A _statement_指定要执行的操作。 ...
单词周围的''_''字符表示
原始文本中的斜体。这是表明这些
条款被视为这些术语定义的标准方式。
这是我发现的(教科书和自己的结论),请
更正错误。
注意:我只是纠正了你的错误;我已经删除了你写的所有内容,其中我发现没有错误(这并不是说没有
错误,只是我没有找到它们。
....
表达式永远不会包含分号。
技术上不正确:c ='';''是一个表达式。但是,表达式
永远不会包含分号作为标记。在那个表达式中,'';''是一个
令牌,但分号字符本身不是。
....
< blockquote class =post_quotes>
如果分号被删除,语句将成为表达式
(尽管对于块语句不是这样)。
对于表达式语句,这是真的,但不一定适用于其他
种类。例如:
返回;
....
1+ + //输入:int。价值:2,对吗?
++的左操作数必须是可修改的左值。它不能是一个
整数文字。
a ++ //类型:取决于a。价值:超过一个。
该表达式的值是在它增加之前的值a / b
。请注意,如果''a''已经达到它的最大值,那么该表达式的行为
是未定义的,除非a具有无符号类型。
....
声明是:
任何以分号分隔的内容,除非它是声明或
for语句中的
表达式。
语句不以分号分隔。声明包括
分号。另请注意,复合语句以''}'终止,
不是分号。最后,请注意声明也以
分号终止。
....
语句是程序结构,后跟分号。
不是复合语句的情况。
....
执行的表达式是一个声明,对吧?
否。执行for(a; b; c)构造中的三个表达式,但
它们都不是语句他们自己。
...一个语句总是原子,即一个语句不能被打破
到sub ;声明。
复合,选择或迭代语句不适用。每个
都包含子语句。
问题:是否可以使用分号进行声明,
分号被删除后,
将不会成为表达式
?
return;
表达式语句的定义是什么,它是如何
与语句和表达式不同?
表达式语句是一种特殊的语句。还有很多其他种类的
。表达式语句包含表达式;它是
本身不是表达式。
它只是一个表达式后跟分号。
是。
块语句的定义是什么?
它是花括号内的一个或多个语句吗?
是。
2007年12月29日星期六16:40:04 +0000,James Kuyper写道:
dspfun写道:
>表达式永远不会包含分号。
技术上不正确:c ='';''是一个表达式。但是,表达式
永远不会包含分号作为标记。在该表达式中,'';''是一个
标记,但分号字符本身不是。
分号可以出现在嵌套在表达式中的声明中。
(struct S {int member;}){0}
以上是struct S类型的完全有效表达式。
Hi!
The words "expression" and "statement" are often used in C99 and C-
textbooks, however, I am not sure of the clear defintion of these
words with respect to C.
Can somebody provide a sharp defintion of "expression" and
"statement"? What is the difference between an expression and a
statement?
This is what I have found (textbooks and own conclusions), please
correct if/where wrong.
-------------------------------------------------
An expression is:
An expression contains data or no data.
Every expression has a type and, if the type is not a void, a value.
An expression can contain zero or more operands, and zero or more
operators.
The simplest expressions consists of a single constant, a variable or
a function call.
An expression can contain an assignment.
An expression never contains a semicolon.
Expressions can be joined with other expressions to form more complex
expressions.
Expressions can serve as operands.
A statement will become an expression if the semicolon is removed
(not true for block statements though).
The values of expressions that starts immediately after a semicolon
and ends immediately before next semicolon are always discarded.
Examples:
4 * 512 //Type: int. Value: 2048.
printf("An example!\n) //Type: int Value: Whatever is returned from
printf.
1.0 + sin(x) //Type: double Value: Whatever is the result of the
expression.
srand((unsigned)time(NULL)) //Type: void. Value: None.
(int*)malloc(sizeof(int)) //Type: int*. Value: The address returned
by malloc.
1++ //Type: int. Value: 2, right?
a++ //Type: Depends on a. Value: One more than a.
x = 5 //Type: depends on the type of variable x, right? Value: 5.
2 * 32767 //Type: depends on INT_MAX, right? Value: 65534
Question: what is the type of the expression above?
a //Type: Depends on a. Value: Depends on a.
1 //Type: int. Value: 1
f() //Type: depends on return type of f(). Value: Depends on what
f() returns.
Right?
In the expressions above the values of the expressions are "thrown
away", right?
Any more examples of expressions which are not the same/variants of
above examples?
-------------------------------------------------
A statement is:
Anything separated by semicolons, unless it''s a declaration or an
expression in a for statement.
Statements specify an action to be performed, such as an operation or
function call.
Statements are program constructs followed by a semicolon.
An expression that is executed is a statement, right?
Statements do not have a value or a type.
A statement specifies an action to be performed, such as an
arithmetic operation of a function call.
Everey statement that is not a block is terminated by a semicolon.
A statement is always "atomic", i.e., a statement cannot be broken
down into "sub" statements.
The following are statements:
Assignment(=)
Compound ({...})
break
continue
goto
label
if
do, while and for
return
switch
Examples of statements:
All the above expressions will become statements when a semicolon is
added to the expression.
Question: Is it possible to have a statement with a semicolon, which
will not become an expression
when the semicolon is removed?
-------------------------------------------------
Also,
What is the defintion of an expression statement, and how is it
different from a statement and an expression?
Is it just an expression followed by a semicolon.
What is the definition of a block statement?
Is it just one or more statements within curly braces?
BRs!
"dspfun" wrote:
The words "expression" and "statement" are often used in C99 and C-
textbooks, however, I am not sure of the clear defintion of these
words with respect to C.
Can somebody provide a sharp defintion of "expression" and
"statement"? What is the difference between an expression and a
statement?I think the only really clear definition comes from a study of the BNF of
the language. (BNF - Backus Normal From/ Backus Naur Form.) Have you
tried Wikipedia?
dspfun wrote:Hi!
The words "expression" and "statement" are often used in C99 and C-
textbooks, however, I am not sure of the clear defintion of these
words with respect to C.
Can somebody provide a sharp defintion of "expression" and
"statement"? What is the difference between an expression and a
statement?Section 6.5p1 says:
"An _expression_ is a sequence of operators and operands that specifies
computation of a value, or that designates an object or a function, or
that generates side effects, or that performs a combination thereof."
Section 6.8p2 says:
"A _statement_ specifies an action to be performed. ..."
The ''_'' characters around a word indicate that it was italicized in the
original text. That is the standard''s way of indicating that these
clauses count as definitions of those terms.
This is what I have found (textbooks and own conclusions), please
correct if/where wrong.Note: I''ve only corrected you where wrong; I''ve cut out everything you
wrote in which I found no error (which is not to say that there were no
errors, only that I didn''t find them).
....An expression never contains a semicolon.Technically incorrect: c = '';'' is an expression. However, expressions
will never contain a semicolon as a token. In that expression, '';'' is a
token, but the semicolon character itself is not.
....A statement will become an expression if the semicolon is removed
(not true for block statements though).This true for expression statements, but not necessarily for other
kinds. Example:
return;
....1++ //Type: int. Value: 2, right?The left operand of ++ must be an modifiable lvalue. It cannot be an
integer literal.
a++ //Type: Depends on a. Value: One more than a.The value of that expression is the value of a before it was
incremented. Note that if ''a'' is already at it''s maximum, the behavior
of that expression is undefined unless a has an unsigned type.
....A statement is:
Anything separated by semicolons, unless it''s a declaration or an
expression in a for statement.Statements are not separated by semicolons. Statements include the
semicolon. Also, note that a compound statement is terminated by a ''}'',
not a semicolon. Finally, note that declarations are also terminated by
semicolons.
....Statements are program constructs followed by a semicolon.Not in the case of compound statements.
....An expression that is executed is a statement, right?No. The three expressions in a for(a; b; c) construct are executed, but
none of them are statements in themselves.
... A statement is always "atomic", i.e., a statement cannot be broken
down into "sub" statements.Not true for compound, selection, or iteration statements. Each of those
contain sub-statements.
Question: Is it possible to have a statement with a semicolon, which
will not become an expression
when the semicolon is removed?return;
What is the defintion of an expression statement, and how is it
different from a statement and an expression?An expression statement is a particular kind of statement. There are
many other kinds. An expression statement contains an expression; it is
not itself an expression.
Is it just an expression followed by a semicolon.Yes.
What is the definition of a block statement?
Is it just one or more statements within curly braces?Yes.
On Sat, 29 Dec 2007 16:40:04 +0000, James Kuyper wrote:dspfun wrote:> An expression never contains a semicolon.
Technically incorrect: c = '';'' is an expression. However, expressions
will never contain a semicolon as a token. In that expression, '';'' is a
token, but the semicolon character itself is not.Semicolons can occur in declarations nested within expressions.
(struct S { int member; }) { 0 }
The above is a perfectly valid expression of type struct S.
这篇关于表达和陈述的定义。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!