tinymux/parser/tokenize.cpp
Stephen Dennis f124a8cd22 Factor shared tokenizer/parser/AST into mux_parse.h
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>
2026-03-07 10:06:59 -07:00

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;
}