Loading the code workspace…
Implement a complete Token structure and supporting types for a C compiler's lexer.
Define a TokenType enum with at least these categories:
TOKEN_INT, TOKEN_RETURN, TOKEN_IF, TOKEN_ELSE, TOKEN_WHILETOKEN_PLUS, TOKEN_MINUS, TOKEN_STAR, TOKEN_SLASH, TOKEN_ASSIGNTOKEN_EQ, TOKEN_NE, TOKEN_LT, TOKEN_GT, TOKEN_LE, TOKEN_GETOKEN_LPAREN, TOKEN_RPAREN, TOKEN_LBRACE, TOKEN_RBRACE, TOKEN_SEMICOLON, TOKEN_COMMATOKEN_NUMBER, TOKEN_IDENTIFIER, TOKEN_STRINGTOKEN_EOF, TOKEN_ERRORDefine a Token struct containing:
Implement helper functions:
token_create(): Allocate and initialize a tokentoken_destroy(): Free token memorytoken_type_to_string(): Return human-readable type namegcc -Wall -WextraEvery production compiler starts here: Clang's Token class and CPython's tokenizer both carry exactly the fields you are defining — kind, text, and source location. Getting location tracking right at the token level is what makes precise error messages like Rust's caret diagnostics possible. A sloppy token design haunts every later compiler phase.