Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Conversation

@skx
Copy link
Owner

@skx skx commented Sep 13, 2020

Once complete this pull-request will implement support for switch statements, which will close #70.

Our switch statement will allow an arbitrary number of case expressions, allowing different blocks of code to be executed depending upon the match.

We allow one default branch in case nothing matches, but this is optional (it is an error to have multiple default cases).

Note that we avoid any confusion with C due to using blocks explicitly, there can be no "fall-thru".

skx added 2 commits September 13, 2020 08:59
We need to add `switch`, `case`, and `default`.
We don't yet use these, but they should be the kind of thing
that we need.  We have two sections:

* One for the "switch .." which contains a series of
* "case ..." expressions, one of which may be a default.
@skx skx self-assigned this Sep 13, 2020
@skx
Copy link
Owner Author

skx commented Sep 13, 2020

PR is function.

TODO:

  • Add test-cases
  • Raise syntax error if there are multiple default cases.
  • Also allow case default as a synonym for default.
  • Allow multiple expressions. e.g. case 1, 2 ,3

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement switch-statements

2 participants