pawn-lang / compiler

Pawn compiler for SA-MP with bug fixes and new features - runs on Windows, Linux, macOS
Other
303 stars 70 forks source link

Remove keywords `*begin`, `*end` and `*then` #681

Open Daniel-Cortez opened 2 years ago

Daniel-Cortez commented 2 years ago

What this PR does / why we need it:

Removes keywords *begin, *end and *then, as well as alternative syntaxes for if, switch, for, while and do-while statements, as explained in #611.

Which issue(s) this PR fixes:

Fixes #611

What kind of pull this is:

Additional Documentation: This PR also includes the changes from #680 (they are needed to prevent a crash in one of the tests), so you'll probably want to review and merge that PR first.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity.

Y-Less commented 2 years ago

Merged locally.

Daniel-Cortez commented 2 years ago

While working on this PR, I noticed one interesting detail:

main()
{
    new x = 0;
    do { ++x; } while x < 10; // this would compile, even though
                              // there are no parentheses around 'x < 10'
}

Apparently, the parentheses around the control expressions of do..while loops are optional. But for some reason they're only optional for do-while loops; in all other control flow statements (while, for, if, switch) parentheses are mandatory. I'm not sure why there's this strange rule for do..while statements, there are no comments about this syntax in the compiler code, and the Language Guide doesn't seem to say anything about this either.

I wonder if this syntax is already used somewhere. Because if not, then removing it would allow to greatly simplify the code in function test() (sc1.c). This PR is about removing excess syntax anyway.