Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ternary operator support #24

Open
3 tasks
alexdovzhanyn opened this issue Aug 3, 2024 · 5 comments
Open
3 tasks

Implement ternary operator support #24

alexdovzhanyn opened this issue Aug 3, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request hacktoberfest A good issue to work on for Hacktoberfest help wanted Extra attention is needed

Comments

@alexdovzhanyn
Copy link
Collaborator

alexdovzhanyn commented Aug 3, 2024

Currently we support control flow operations such as if / else if / else. You can assign variables to the result of control flow operations like so:

x<String> = if (1 == 1) 'Yes' else 'No'

This works fine, but it would be nice to add some syntactic sugar so we could also do:

x<String> = 1 == 1 ? 'Yes' : 'No'

In order to allow for this, we need to update the parser to recognize this as a control flow node.

  • Update the lexer to allow for ? tokens
  • Update the parser to turn ternary operations into ControlFlowNodes
  • Add tests to the lexer, parser, and codegen to verify the changes
@alexdovzhanyn alexdovzhanyn added enhancement New feature or request help wanted Extra attention is needed labels Aug 3, 2024
@alexdovzhanyn alexdovzhanyn added the hacktoberfest A good issue to work on for Hacktoberfest label Sep 23, 2024
@syfuuu
Copy link

syfuuu commented Sep 29, 2024

@alexdovzhanyn I can work on this. Please assign this to me.

@alexdovzhanyn
Copy link
Collaborator Author

@syfuuu You got it!

@syfuuu
Copy link

syfuuu commented Sep 29, 2024

Hey, Are you sure x<String> = if (1 == 1) 'Yes' else 'No' works? its giving me segmentation fault. I already worked on lexer but parser is but tricky. Try to understand how it works incase of if/else. Is there any communication channel for discussing things related to this project?

@alexdovzhanyn
Copy link
Collaborator Author

@syfuuu Yeah it should work, though there may be a bug. It looks like currently if (1 == 1) 'Yes' else 'No' gets parsed correctly, however it fails if you try to assign it to a variable like x<String> = if (1 == 1) 'Yes' else 'No'. I'll make a separate bug ticket for that. But for now you can build the ternary based on if (1 == 1) 'Yes' else 'No'.

We have a discord channel here, feel free to hop in.

@alexdovzhanyn
Copy link
Collaborator Author

@syfuuu I've made another issue to track that bug here: #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest A good issue to work on for Hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants