Questions tagged [expressions]

For questions relating to expressions, or code that gets evaluated to a single value, in programming languages.

Filter by
Sorted by
Tagged with
2 votes
3 answers

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 ...
DannyNiu's user avatar
  • 231
10 votes
3 answers

What is a "primary expression"?

I've found that many grammars have a production called PrimaryExpression or something along those lines. ECMAScript has ...
Lazar Ljubenović's user avatar
2 votes
1 answer

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 ...
justANewbie's user avatar
8 votes
3 answers

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 ...
Panda's user avatar
  • 249
9 votes
5 answers

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 ...
user16217248's user avatar
  • 7,535
9 votes
3 answers

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 ...
Aman Grewal's user avatar
13 votes
8 answers

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 ...
The Empty String Photographer's user avatar
4 votes
4 answers

How would I describe an expression seperately 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 ...
user16217248's user avatar
  • 7,535
10 votes
5 answers

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 ...
bigyihsuan's user avatar
  • 1,663
7 votes
5 answers

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. ...
Dannyu NDos's user avatar