单个常量值是否被视为表达式?
Is a single constant value considered an expression?
阅读 一个 CSS 问题后,我想知道:
在计算机科学中,单个常量值是否被视为表达式?
也就是说,7px
是一个表达式吗?只是 7
怎么样?
引用 Wikipedia,强调我的:
An expression in a programming language is a combination of one or more explicit values, constants, variables, operators, and functions that the programming language interprets [...] and computes to produce [...] another value. This process, as for mathematical expressions, is called evaluation.
引用 MS Docs,强调我的:
An expression is a sequence of one or more operands and zero or more operators that can be evaluated to a single value, object, method, or namespace. Expressions can consist of a literal value [...].
这两个似乎都表明值是表达式。但是,有人可能会争辩说不会评估一个值,因为它已经只是一个值,因此不符合条件。
引用 Techopedia,强调我的:
[...] In terms of structure, experts point out that an expression inherently needs at least one 'operand’ or value that is acted on, and must have one or more operators. [...]
这表明甚至 x
也不符合表达式的条件,因为它缺少 一个或多个运算符。
这当然取决于确切的定义,但在大多数定义下,表达式是递归定义的,常量是基本情况之一。所以,是的,文字值是表达式的特例。
您可以查看各种语言的语法,例如 one for Python
如果您跟踪语法,您会发现 expr
可以是包含数字文字的 atom
。数字字面量是 Python 表达式这一事实在您考虑产生式时也很明显:
comparison: expr (comp_op expr)*
这是捕获 x < 7
等表达式的产生式,如果 7
不是有效表达式,则不会捕获该表达式。
In Computer Science, is a single, constant value considered an expression?
这完全取决于上下文。例如,FORTRAN、BASIC 和 COBOL 都有行号。这些是不是表达式的数字常量值。
在其他上下文中(甚至在那些语言中)数字常量可能是一个表达式。
阅读
在计算机科学中,单个常量值是否被视为表达式?
也就是说,7px
是一个表达式吗?只是 7
怎么样?
引用 Wikipedia,强调我的:
An expression in a programming language is a combination of one or more explicit values, constants, variables, operators, and functions that the programming language interprets [...] and computes to produce [...] another value. This process, as for mathematical expressions, is called evaluation.
引用 MS Docs,强调我的:
An expression is a sequence of one or more operands and zero or more operators that can be evaluated to a single value, object, method, or namespace. Expressions can consist of a literal value [...].
这两个似乎都表明值是表达式。但是,有人可能会争辩说不会评估一个值,因为它已经只是一个值,因此不符合条件。
引用 Techopedia,强调我的:
[...] In terms of structure, experts point out that an expression inherently needs at least one 'operand’ or value that is acted on, and must have one or more operators. [...]
这表明甚至 x
也不符合表达式的条件,因为它缺少 一个或多个运算符。
这当然取决于确切的定义,但在大多数定义下,表达式是递归定义的,常量是基本情况之一。所以,是的,文字值是表达式的特例。
您可以查看各种语言的语法,例如 one for Python
如果您跟踪语法,您会发现 expr
可以是包含数字文字的 atom
。数字字面量是 Python 表达式这一事实在您考虑产生式时也很明显:
comparison: expr (comp_op expr)*
这是捕获 x < 7
等表达式的产生式,如果 7
不是有效表达式,则不会捕获该表达式。
In Computer Science, is a single, constant value considered an expression?
这完全取决于上下文。例如,FORTRAN、BASIC 和 COBOL 都有行号。这些是不是表达式的数字常量值。
在其他上下文中(甚至在那些语言中)数字常量可能是一个表达式。