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

Fix incorrect lexing of "$ff00+c" #882

Merged
merged 2 commits into from
May 5, 2021
Merged

Fix incorrect lexing of "$ff00+c" #882

merged 2 commits into from
May 5, 2021

Conversation

ISSOtm
Copy link
Member

@ISSOtm ISSOtm commented May 4, 2021

Fixes #881 by moving the task from the lexer to the parser.
This both alleviates the need for backtracking in the lexer, removing what is (was) arguably a hack, and causes tokenization boundaries to be properly respected, fixing the issue mentioned above.

Fixes gbdev#881 by moving the task from the lexer to the parser.
This both alleviates the need for backtracking in the lexer,
removing what is (was) arguably a hack, and causes tokenization
boundaries to be properly respected, fixing the issue mentioned above.
@ISSOtm ISSOtm added bug Unexpected behavior / crashes; to be fixed ASAP! rgbasm This affects RGBASM labels May 4, 2021
@ISSOtm ISSOtm requested a review from Rangi42 May 4, 2021 23:38
@ISSOtm
Copy link
Member Author

ISSOtm commented May 4, 2021

We tried similar fixes some time ago, and they produced grammar conflicts; I did not get any on my machine (Bison 3.7.6), so I'm making this PR to check that this is also the case on other platforms.

src/asm/parser.y Outdated
| T_LBRACK relocexpr T_OP_ADD T_MODE_C T_RBRACK {
int32_t val = rpn_GetConstVal(&$2);

if (val != 0xff00) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid potentially two error messages here, I would do:

if (!rpn_isKnown(&$2) || $2.val != 0xff00)
    error("Expected constant expression equal to $FF00 for \"$ff00+c\"");

Copy link
Contributor

Choose a reason for hiding this comment

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

(The "(did you mistype the C?)" is also unusual for RGBDS error messages.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Unusual, certainly, but is that a bad thing? This is a weird edge case of the parser, so guiding users into likely error causes should be a win, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the "equal to $FF00" is clear enough if they try something like ld [$c200+c], a.

Copy link
Member Author

@ISSOtm ISSOtm May 4, 2021

Choose a reason for hiding this comment

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

I'm considering

cd = 420

ld [$C200 + c], a ; Oops, I forgot the `d` in `cd`!

Copy link
Contributor

Choose a reason for hiding this comment

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

Then they look at the line and see the +c typo. bg equ $42 / ld [$c200+b], a just says "syntax error, unexpected b".

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I guess.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't really mind if "did you mistype the C?" were very likely to be helpful advice, but it's misleading in the cases where the not-$ff00-number is the mistake.

@ISSOtm
Copy link
Member Author

ISSOtm commented May 4, 2021

This does appear to produce no conflicts, go figure. Maybe some grammar changes? :S

@ISSOtm ISSOtm merged commit c06985a into gbdev:master May 5, 2021
@ISSOtm ISSOtm deleted the fix-ff00c branch May 5, 2021 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behavior / crashes; to be fixed ASAP! rgbasm This affects RGBASM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$ff00 + csymbol is lexed incorrectly
2 participants