Skip to main content

Questions tagged [expressions]

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

2 votes
3 answers
944 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 ...
DannyNiu's user avatar
  • 229
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 ...
Lazar Ljubenović's user avatar
2 votes
1 answer
155 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 ...
justANewbie's user avatar
  • 1,030
8 votes
3 answers
167 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 ...
Panda's user avatar
  • 249
9 votes
5 answers
431 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 ...
CPlus's user avatar
  • 8,803
9 votes
3 answers
271 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 ...
Aman Grewal's user avatar
13 votes
8 answers
783 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 ...
The Empty String Photographer's user avatar
4 votes
5 answers
300 views

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 ...
CPlus's user avatar
  • 8,803
10 votes
5 answers
252 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 ...
bigyihsuan's user avatar
  • 1,821
7 votes
5 answers
478 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. ...
Dannyu NDos's user avatar