Skip to content

Conversation

@mattcce
Copy link
Contributor

@mattcce mattcce commented Nov 10, 2025

CSEC: Prefix/Postfix Expressions

This PR aims to implement prefix/postfix expressions for a restricted subset of possible lvalues for the CSEC machine.

The CSEC machine presently does not have any implementation available for any prefix/postfix expression kind.

Lvalues

Common lvalues (read: may not be an exhaustive list) in Java include:

  • variable names,
  • array access expressions, and
  • field access expressions.

This PR only targets prefix/postfix expressions for variable names. The other lvalue types are not in scope for this PR.

Prefix Expression

A prefix expression:

  1. performs the operation and assignment, then
  2. evaluates to the final value referenced by the lvalue.
  • Preconditions: None.
  • Postconditions:
    1. the lvalue has its value set to the value after applying the relevant binary operation to the original value.
    2. the top of the stash contains the final value referenced by the lvalue.

To implement this, we give prefix expressions the control expansion:

  • C, PrefixExpression -> C, <name>, <assignment-statement>

where:

  • <name> is the variable name that occurs in the prefix expression, and
  • <assignment-statement> is the equivalent updating assignment statement required by the prefix expression.

Postfix Expression

A postfix expression:

  1. performs the operation and assignment, then
  2. evaluates to the original value referenced by the lvalue.
  • Preconditions: None.
  • Postconditions:
    1. the lvalue has its value set to the value after applying the relevant binary operation to the original value.
    2. the top of the stash contains the original value referenced by the lvalue.

To implement this, we give postfix expressions the control expansion:

  • C, PostfixExpression -> C,<assignment-statement>, <name>

where:

  • <name> is the variable name that occurs in the postfix expression, and
  • <assignment-statement> is the equivalent updating assignment statement required by the postfix expression.

Original implementation by @Isha-Sovasaria, changes have since gone stale.

Will aim to take over this feature from here on out.

@mattcce mattcce self-assigned this Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants