Questions tagged [expressions]
For questions relating to expressions, or code that gets evaluated to a single value, in programming languages.
10 questions
2
votes
3
answers
1k
views
How to support syntax like `a && b = c` for a conditional assignment expression?
I want the expression a && b = c in my language to mean that the value of c is assigned to ...
10
votes
3
answers
2k
views
What is a "primary expression"?
I've found that many grammars have a production called PrimaryExpression or something along those lines. ECMAScript has ...
2
votes
1
answer
187
views
What are the pros and cons of having assignment expressions? [duplicate]
Some languages (for example C and C++) have assignment expressions, which means the assignment statement as a whole returns a value of the object specified by the left operand after the assignment.
So ...
8
votes
3
answers
176
views
Relative precedence of let and if expressions
In a language with standard let and if expressions, what should be the their precedence such that they can be nested without parentheses?
For example, I want to be able to parse both of these ...
9
votes
5
answers
521
views
What would a for loop return in an expression oriented language?
An expression-oriented language sounds appealing, as I could have code logic inline in expressions and initializers. An if statement could just return the last ...
9
votes
3
answers
343
views
What are the advantages/disadvantages of distinguishing statements and expressions?
Some languages distinguish expressions from statements so that something like
int x = 2;
foo((x += 2));
is invalid.
Other languages don't, so that a similar
...
13
votes
8
answers
1k
views
Pros and cons of throwing an error versus returning a NaN value
So I've seen that many languages return a NaN value when calculating an indeterminate arithmetic expression (e.g. 0/0). Other ...
4
votes
6
answers
421
views
How would I describe an expression separately from a statement?
I have thought about how I could specify an expression separate from a statement.
A fragment of code that resolves to a value.
But void expressions are still ...
10
votes
5
answers
275
views
Allowing `}` as a statement terminator in an expression-based language?
My language is expression based; many of its language constructs are not statements, but rather expressions that return a value. However, since everything is an expression, my grammar looks like
...
7
votes
5
answers
515
views
Why are expressions in languages so prone to integer overflow?
I've always wondered. Why do major languages let their addition and multiplication operators be so prone to integer overflow? My programming language would have separate operators to handle overflow. ...