mirror of
https://github.com/brazilofmux/tinymux
synced 2026-08-13 00:23:11 -04:00
Extract duplicated tokenizer, parser, and AST code from three study tools into a shared header. Each tool is now a thin main() wrapper. Added ast_raw_text() utility for source reconstruction. No behavioral changes — 78 tests still pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
31 lines
780 B
C++
31 lines
780 B
C++
/*
|
|
* tokenize.cpp - MUX expression tokenizer study tool.
|
|
*
|
|
* Reads MUX expressions from stdin (one per line) and emits a token
|
|
* stream to stdout. Stage 1 of the parser study.
|
|
*/
|
|
|
|
#include "mux_parse.h"
|
|
|
|
int main()
|
|
{
|
|
char line[8192];
|
|
while (fgets(line, sizeof(line), stdin)) {
|
|
size_t len = strlen(line);
|
|
if (len > 0 && line[len - 1] == '\n') {
|
|
line[len - 1] = '\0';
|
|
}
|
|
|
|
printf("INPUT: %s\n", line);
|
|
auto tokens = tokenize(line);
|
|
for (const auto &tok : tokens) {
|
|
if (tok.type == TOK_EOF) {
|
|
printf(" EOF\n");
|
|
} else {
|
|
printf(" %-7s \"%s\"\n", token_name(tok.type), tok.text.c_str());
|
|
}
|
|
}
|
|
printf("\n");
|
|
}
|
|
return 0;
|
|
}
|