ECE-492-SnakesAndAdders / python-interpreter

C3Python is an entirely custom-made Python interpreter designed to run on proprietary hardware.
Creative Commons Attribution 4.0 International
0 stars 0 forks source link

BUG: Some reserved keywords are not identified properly #1

Closed ijoffe closed 7 months ago

ijoffe commented 8 months ago

There is an issue in some reserved keywords tokens being printed.

image

The first row of reserved keywords print correctly (although IF, ELIF, and ELSE print weirdly sometimes). But after that, they usually aren't identified as keywords. The FOR row doesn't work at all, but the ones below sometimes work (although they don't print).

image

I know that it is not an issue with Lexer::iskeyword() -- the following code prints each keyword as expected:

char * setup = "print(\"Hello World\")";
Lexer lexer(&setup);
for (uint16_t i = 0; i <= DEL; i++) {
    lexemes x = (lexemes) i;
    char y[15] = "";
    char * z = (char *) y;
    uint16_t j = 0;
    while (names[x][j] != '\0') {
        *(y + j) = (names[x][j] >= 65 && names[x][j] <=90) ? (names[x][j] + 32) : (names[i][j]);
        j++;
    }
    xpd_puts(names[x]);
    xpd_putc(' ');
    xpd_puts(z);
    xpd_putc(' ');
    xpd_puts(names[lexer.iskeyword(&z)]);
    xpd_putc('\n');
}
return 0;

image

I have no clue why this error happens.

ijoffe commented 7 months ago

image

Resolved by not using the strcmp() function, which seems to have some unknown issues (it works when I test it directly, but fails in practice). Fixed by more manual code that I am not proud of.

I manually tested each and confirmed it all works.

After lexeme #72, undefined names are printed (OOM?). After #76, they are usually just printed blank.