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>
27 lines
663 B
C++
27 lines
663 B
C++
/*
|
|
* parse.cpp - MUX expression recursive-descent parser study tool.
|
|
*
|
|
* Reads MUX expressions from stdin (one per line), tokenizes them,
|
|
* then builds an AST and prints it. Stage 2 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);
|
|
Parser parser(tokens);
|
|
auto ast = parser.parse();
|
|
ast_print(ast.get(), 2);
|
|
printf("\n");
|
|
}
|
|
return 0;
|
|
}
|