Skip to content

[Bug]: escaped char literals ('\n', '\t', ...) fail to parse — lexer returns YAP instead of CHAR #373

Description

@leo-aa88

Description

An escaped character literal ('\n', '\t', '\\', '\'', '\0', …) fails to parse. The lexer rule that matches escaped char literals returns the token YAP — which is the yap/char type keyword token — instead of a CHAR literal token, so the parser sees a type keyword where an expression is required and aborts.

Plain single-character literals ('a') work, because they are matched by a different rule that correctly returns CHAR.

Minimal reproduction code

skibidi main {
    yap c = '\n';
    yapping("%d", c);
    bussin 0;
}

Expected behavior

Prints 10 (the code point of newline) and exits 0 — just as yap c = 'a'; correctly prints 97.

Actual behavior

$ ./brainrot escape.brainrot
Error: syntax error, unexpected YAP at line 1
Parsing failed

Exit code 1. Every escape sequence in a char literal is affected.

Brainrot version / commit

19b9563

Operating system

Ubuntu on WSL2 (Linux 5.15)

Additional context

Root cause: lang.l. The escaped-char-literal rule \'([^\\\']|\\.)\' decodes the escape correctly into yylval.ival but ends with return YAP;. YAP is the type keyword token ("yap" { current_var_type = VAR_CHAR; return YAP; }). The plain-char rule '.' correctly does return CHAR;. The escaped-char rule should also return CHAR;.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions