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

Move block statement to statement #53

Merged
merged 2 commits into from
Nov 30, 2023

Conversation

leewei05
Copy link
Contributor

  • Move block statement to statement
  • Support single statement for if statement
  • Fix dangling else problem

@leewei05 leewei05 requested a review from Lai-YT November 30, 2023 07:52
@leewei05 leewei05 self-assigned this Nov 30, 2023
Copy link
Collaborator

@Lai-YT Lai-YT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's essential to distinguish between blocks and normal statements since blocks cannot always be replaced by a statement. Consider the main_func as an example, which must have its body enclosed within a pair of curly braces.
Allowing any statement to represent its body could result in syntactically valid, yet unintended code like the following Python-ish syntax:

int main()
    return 0;

For reference, in the C standard ISO/IEC 9899:1999, section 6.9.1 defines the syntax of a function-definition:

  • function-definition:
    declaration-specifiers declarator declaration-listopt compound-statement

Here, the compound-statement corresponds to our block-statement.

parser.y Show resolved Hide resolved
Copy link
Collaborator

@Lai-YT Lai-YT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create a test for the if_else_single_stmt, possibly a nested one as well!

test/typecheck/if_single_stmt.c Outdated Show resolved Hide resolved
@leewei05 leewei05 force-pushed the move-block-to-stmt branch 3 times, most recently from 35f7d06 to 6cfe5f7 Compare November 30, 2023 15:02
@leewei05 leewei05 requested a review from Lai-YT November 30, 2023 15:03
parser.y Outdated Show resolved Hide resolved
Copy link
Collaborator

@Lai-YT Lai-YT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, for the proper support of the if statement! 🎉
We're now closer to the moon. 🚀

@Lai-YT Lai-YT merged commit 063afd2 into fruits-lab:main Nov 30, 2023
3 checks passed
@leewei05 leewei05 deleted the move-block-to-stmt branch December 1, 2023 15:40
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.

2 participants