问题标签 [expression-evaluation]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - 为什么不同的 C++ 编译器对这段代码给出不同的结果?
我正在编写一些 C++ 代码以供娱乐和练习,以了解有关语言功能的更多信息。我想更多地了解静态变量及其在递归函数中的行为。在 g++ 编译器中尝试这段代码,我得到了预期的结果:
但是我的朋友在 Microsoft Visual C++ 6 中测试了相同的代码。输出是50, 80, 90
我用其他 C++ 编译器(Linux、Win 和 Mac 下的 g++、Borland、Code::blocks 和 MingW)测试它的输出是110, 100, 40
. 我无法理解输出如何50, 80, 90
......
为什么 MSVC 的输出不同?
c# - ReSharper 错误?不正确的“表达式总是正确的”
我相信我在 ReSharper 中发现了一个错误。假设我有如下代码:
如果局部变量 someArray 在其范围内未分配给 null,则该语句someArray != null
将始终为真。但是,当该变量作为 ref 参数提供给另一个方法时,情况并非如此,因为它可以在该方法中被分配给 null。然后 ReSharper 错误地假设这someArray != null
仍然是正确的。
我想我会分享这些信息,因为我不确定我应该如何处理它。首先,我希望有人验证此错误,然后将其发送给 JetBrains?
scheme - Scheme: Proper application of the eval function?
at work I encountered a basic problem when trying to implement a configuration script with Scheme. To avoid the need of inventing an artificial and restricted language the script should contain actual code. This code shall be evaluated later on. To make the configuration work as desired it has to have access to certain variables. These variables are only known in the context of the evaluation. Therefore the configuration script has to be evaluated in the current environment. Here is a primitive example of what I am talking about:
When running this code I'd always get an error message telling me that the variable 'a' is unknown. So the question is: Do you know how to evaluate frozen code inside the current environment?
P.S.: I use the bigloo compiler.
///////////////////////////////////////////// EDIT: //////////////////////////////////////////////////////
When using the approach suggested by Chris I came to another interesting problem, the usage of the case keyword. The following two examples both use the same case construction which should trigger the output of a "yes!" line. Unfortunately they behave differently.
Usual -> output is "yes!" as expected:
With eval -> output is surprisingly "no":
Does that make any sense?
c - C 中的表达式求值
为什么下面这段 C 代码打印出来12 12 12
c# - 在 Irony 中定义常量和运算符
我是Irony和整个语言实现 shebang 的新手,所以我一直在玩Irony 源附带的ExpressionEvaluator示例,这似乎(几乎)适合我正在处理的项目的需求。
但是,我希望它也支持布尔值,因此我将比较运算符添加到二元运算符列表中,如下所示:
这是我要实现的目标的示例:
由于添加了二元运算符,它成功解析了上述内容。但是,在编译和运行代码时,它在最后两行失败。
- 该
bool = true
行失败并显示消息:错误:未定义变量 true。在 (5:8)。如何将true和false定义为常量? - 该
bool2 = (eval == eval2)
行失败并显示以下消息:错误:未为 System.Boolean 和 System.Boolean 类型定义运算符“==”。在(6:15)。
编辑:解决了这两个问题,请参阅下面的答案。
c# - 评估清单作为数学表达式
我有一个List<String>
充满价值观和运营商的东西。
我知道我可以制作一个算法,将这些数字和运算符推入堆栈,然后将它们弹出并在我进行时进行评估。但是,不使用外部库有没有更好的方法呢?
c++ - c ++,评估具有多个`&&`的表达式并且没有较低优先级的运算符
如果一个表达式计算多个&&
运算符,并且不计算任何较低优先级的运算符(例如||
, ?:
),那么只要其中一个&&
s 返回 0,表达式就会计算为 0,还是会完成对剩余&&
s 的计算?
例如,
if()
一旦评估为 0,这是否会评估为 false(因为无论右手运算符如何, q && w
其余部分都必须全部评估为 0)?&&
c# - Building a boolean function from a string description
I have a large database of boolean values and want to build a framework for easily running queries over all of the values. To do this, I'd like to write a function that, given a string representation of a boolean expression, would evaluate that expression over all of the elements of the database. For example, given input
The function would construct another function that would evaluate
where funcA
, funcB
, and funcC
are functions returning booleans
delphi - Delphi Prism:替换 TMathparser 类以评估复杂表达式?
在 Delphi 中,我使用一个名为 TMathparser 的组件来评估表达式以获得答案。我试图让它在 Delphi Prism 中工作,但效果不太好。事实上,错误太多了。所以,我想知道是否有类似的东西可以与 Delphi Prism 一起使用。
谢谢,
antlr - ANTLR : 表达式求值器,除法和 pow
我正在尝试编写一个语法来评估表达式。
我从 ANTLR 网站上的给定示例开始(它管理 +、- 和 *)。我添加了分区。但是如果他试图除以 0,我想通知用户。此外,我想在我的评估器中添加 pow(优先级高于乘法和除法。(例如 2^3=8)。
希望这是可以理解的.
这是我的语法 Expr.g :
提前致谢。埃德。